using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
namespace test
{
/// <summary>
/// Service1 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[SoapRpcService]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
// [System.Web.Script.Services.ScriptService]
public class hello : System.Web.Services.WebService
{ [SoapRpcMethod, WebMethod]
public string HelloWorld()
{
return "Hello World";
}
}
}web service 最基本的asp.net的web servicepackage org.stu;import java.io.IOException;import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;import android.app.Activity;
import android.os.Bundle;
import android.widget.EditText;
public class StuActivity extends Activity
{
String nameSpace = "http://tempuri.org/";
String methodName = "HelloWorld";
String url = "http://www.stu80.com/hello.asmx";
private EditText txt1;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
txt1 = (EditText) findViewById(R.id.txt1);
// 调用的方法
String methodName = "HelloWorld";
// 创建HttpTransportSE传输对象
HttpTransportSE ht = new HttpTransportSE(url);
ht.debug = true;
// 使用SOAP1.1协议创建Envelop对象
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11 );
// 实例化SoapObject对象
SoapObject soapObject = new SoapObject(nameSpace, methodName);
// soapObject.addProperty("param", "1");
// 将soapObject对象设置为 SoapSerializationEnvelope对象的传出SOAP消息
envelope.bodyOut = soapObject;
try
{
// 调用Web Service
ht.call(null, envelope);
if (envelope.getResponse() != null)
{
// 获取服务器响应返回的SOAP消息
SoapObject result = (SoapObject) envelope.bodyIn;
txt1.setText(result.toString());
}
}
catch (IOException e)
{
e.printStackTrace();
}
catch (XmlPullParserException e)
{
e.printStackTrace();
}
}
}
问题是报错怎么做?web service 地址 http://www.stu80.com/hello.asmx,大家可以试试,寻找解决方法
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
namespace test
{
/// <summary>
/// Service1 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[SoapRpcService]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
// [System.Web.Script.Services.ScriptService]
public class hello : System.Web.Services.WebService
{ [SoapRpcMethod, WebMethod]
public string HelloWorld()
{
return "Hello World";
}
}
}web service 最基本的asp.net的web servicepackage org.stu;import java.io.IOException;import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;import android.app.Activity;
import android.os.Bundle;
import android.widget.EditText;
public class StuActivity extends Activity
{
String nameSpace = "http://tempuri.org/";
String methodName = "HelloWorld";
String url = "http://www.stu80.com/hello.asmx";
private EditText txt1;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
txt1 = (EditText) findViewById(R.id.txt1);
// 调用的方法
String methodName = "HelloWorld";
// 创建HttpTransportSE传输对象
HttpTransportSE ht = new HttpTransportSE(url);
ht.debug = true;
// 使用SOAP1.1协议创建Envelop对象
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11 );
// 实例化SoapObject对象
SoapObject soapObject = new SoapObject(nameSpace, methodName);
// soapObject.addProperty("param", "1");
// 将soapObject对象设置为 SoapSerializationEnvelope对象的传出SOAP消息
envelope.bodyOut = soapObject;
try
{
// 调用Web Service
ht.call(null, envelope);
if (envelope.getResponse() != null)
{
// 获取服务器响应返回的SOAP消息
SoapObject result = (SoapObject) envelope.bodyIn;
txt1.setText(result.toString());
}
}
catch (IOException e)
{
e.printStackTrace();
}
catch (XmlPullParserException e)
{
e.printStackTrace();
}
}
}
问题是报错怎么做?web service 地址 http://www.stu80.com/hello.asmx,大家可以试试,寻找解决方法
解决方案 »
- libcore.java.io.InterruptedStreamTest#testInterruptWritablePipeChannel测试项未通过
- android 蓝牙游戏 数据传递
- Help g711用java写的编解码例子
- android获取当前正启动的应用程序(获取启动时间),关闭当前应用(获取关闭应用时间)
- 100分!求助!怎么在mm编译时强行把某几个文件编到APK的根目录下
- 请问如何在非Activity类中得到Context
- 请高手帮我看下如下Android代码,问题在哪里
- 手机休眠后感应器不工作问题
- 改变屏幕方向的一个小程序,大家帮忙看看
- 新手求助!关于spinner 获取值问题
- android状态栏中信号强度图标的大小怎么修改?
- Android 怎么彻底关闭GPS
2 ht.call(nameSpace+methodName, envelope); //第一个参数action的值为命名空间+方法名
你还来劲了,又不是什么非常复杂的web service,就一个asp.net创建web service时的默认的Hello World
函数,主程序就这么几行,,也可以复制啊,又不要手打的main.xml 就一个TextView啊,又不是很多很多既然你这么说了,那我也要说了,你就不能新建一个android项目,调试一下啊不说就算了,反正浪费了几百分了,不差这100分。。