解决方案 »
- android连接Webservice问题! 万急!!!
- 有关/sys/power/state设置系统状态
- 发送同一个Message出现的错误
- 类中没有继承MapActivity的选项。
- 我想搞清楚Content provider到底是啥
- 解析XML遇到的异常 ExpatParser$ParseException
- 翻页特效
- 黑马程序员_我的九九乘法表循环
- Android基于Xmpp协议openfire+asmack实现视频通信
- Android中的asynchttpclient框架post成功后无法执行list.add方法
- Android游戏开发 点击图片按钮实现返回上一个View的效果
- 使用aapt获取apk信息的乱码问题
用httpclient吧,android自带了,省事点
把你邮箱给我,我发给你我用的例子代码,注释也比较全的
记得自己去网上下载这个jar包:ksoap2-android-assembly-2.4-jar-with-dependencies.jarprivate 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;
}