android 平台下生成webService代理类的工具 http://code.google.com/p/ksoap2-android/ 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这个工具是给android使用,专门用于调用WS接口的,使用很方便,网上也有大量使用的例子 去网上下载这个jar包:ksoap2-android-assembly-2.4-jar-with-dependencies.jar使用方法如下:public class TestWebService extends Activity { private static String NameSpace="http://tempuri.org/"; private static String u="http://10.8.8.70:808";//请更换成你要访问的服务器地址 private static String webService="/webService/WebService.asmx";//webService目录 private static String MethodName="HelloWorld2";//要调用的webService方法 private static String soapAction=NameSpace+MethodName; private static String url=u+webService; private TextView tv; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); tv=(TextView)findViewById(R.id.tv); tv.setText(ws()); } //webService操作要访问网络,所以最好是使用线程来做,这里只是示例,所以就不考虑了 private String ws(){ String result=""; try{ SoapObject request=new SoapObject(NameSpace,MethodName);//NameSpace //webService方法中的参数,这个根据你的webservice来,可以没有。 //但请注意,参数名称和参数类型客户端和服务端一定要一致,否则将可能获取不到你想要的 //request.addProperty("x",5); //request.addProperty("y", 6); SoapSerializationEnvelope envelope=new SoapSerializationEnvelope( SoapEnvelope.VER11); envelope.dotNet=true; envelope.setOutputSoapObject(request); HttpTransportSE ht=new HttpTransportSE(url); ht.call(soapAction, envelope); if(envelope.getResponse()!=null){ SoapPrimitive response=(SoapPrimitive)envelope.getResponse(); result=response.toString();//这里获得了webService的返回值 } }catch(Exception e){ result=e.getMessage(); } return result; }} jdk1.6以上支持命令行获取服务的代码,wsinport xxxxx,把相关代码搞到手,具体使用方法你可以查,不需要第三方jar 老外有写了这样的生成工具,网址是:http://code.google.com/p/android-ws-client/downloads/list可以一起研究一下,我碰到了跟你同样的问题。 老外写了一个Android端上能生成WebService代理类的工具,谁有兴趣一起研究一下,老外的网址是:http://code.google.com/p/android-ws-client/ 有没有android在条形码和二维码下的案例 关于android的学习方向问题?新人求解 android中,RTC如何设置? android的一些基本类 C#和java base64编码 上传到服务器 图片不能还原 关于handler的问题,求大神们解答一下 奇怪的布局文件,明明没错 看了Android深入浅出 有点问题问问 请教这种动画怎么做的?谢谢 popupWindow 弹出另一个PopupWindow出现问题 关于3.0版本的android.graphics.Canvas.getGL没有了的问题 怎样列出/data/data/mypackage/files目录下的文件结构
使用方法如下:public class TestWebService extends Activity {
private static String NameSpace="http://tempuri.org/";
private static String u="http://10.8.8.70:808";//请更换成你要访问的服务器地址
private static String webService="/webService/WebService.asmx";//webService目录
private static String MethodName="HelloWorld2";//要调用的webService方法
private static String soapAction=NameSpace+MethodName;
private static String url=u+webService;
private TextView tv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv=(TextView)findViewById(R.id.tv);
tv.setText(ws());
}
//webService操作要访问网络,所以最好是使用线程来做,这里只是示例,所以就不考虑了
private String ws(){
String result="";
try{
SoapObject request=new SoapObject(NameSpace,MethodName);//NameSpace
//webService方法中的参数,这个根据你的webservice来,可以没有。
//但请注意,参数名称和参数类型客户端和服务端一定要一致,否则将可能获取不到你想要的
//request.addProperty("x",5);
//request.addProperty("y", 6);
SoapSerializationEnvelope envelope=new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.setOutputSoapObject(request);
HttpTransportSE ht=new HttpTransportSE(url);
ht.call(soapAction, envelope);
if(envelope.getResponse()!=null){
SoapPrimitive response=(SoapPrimitive)envelope.getResponse();
result=response.toString();//这里获得了webService的返回值
}
}catch(Exception e){
result=e.getMessage();
}
return result;
}
}
http://code.google.com/p/android-ws-client/downloads/list
可以一起研究一下,我碰到了跟你同样的问题。
谁有兴趣一起研究一下,老外的网址是:
http://code.google.com/p/android-ws-client/