String namespace ="http://tempuri.org/";
String endpoint = "http://116.55.248.28:9999/UserInfoService.asmx";
String method = "CheckUserLoginIsExit";
String SOAPAction = "http://tempuri.org/CheckUserLoginIsExit";
SoapObject request = new SoapObject(namespace, method);
request.addProperty("UserLogin", "muou");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.encodingStyle="UTF-8";
envelope.bodyOut=request;
envelope.dotNet=true;
//envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(endpoint);
try {
androidHttpTransport.call(SOAPAction, envelope);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//SoapObject object = null;
SoapObject object = (SoapObject )envelope.bodyIn;
if(object==null){
Toast.makeText(getApplicationContext(), "object is null", Toast.LENGTH_LONG).show();
}
为什么object输出的结果是null???不知道问题的所在
解决方案 »
- android平板用linux?
- Android2.3 ndk opengles如何显示yuv格式图片
- Android中ListView按上下键滚屏不刷新,求指教
- 读取sdcard卡上出现滴问题
- 手机开发大杂烩
- android高手来帮帮我啊啊啊啊啊啊啊啊啊啊啊啊。。。
- 关于Service中的callback问题
- 怎样动态更新gridview的某个item
- ANDROID如何设置移动专网APN
- 在flutter 中如何判断应用程序处于前台还是后台
- 百度地图Apiandroid公交车搜索transitOverlay类 提示找不到:icon_nav_start_h.png
- java、Android与Red5的通讯组件juv-rtmp-client
可以的话就结贴吧public class TestWebService extends Activity {
private static String NameSpace="http://tempuri.org/";//这个不要改
//http://116.55.248.28:9999/UserInfoService.asmx
private static String u="http://116.55.248.28:9999";//请更换成你要访问的服务器地址
private static String webService="/UserInfoService.asmx";//webService目录
private static String MethodName="CheckUserLoginIsExit";//要调用的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("UserLogin", "muou");
//request.addProperty("y", 6);
SoapSerializationEnvelope envelope=new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet=true;//访问.NET的webservice
envelope.setOutputSoapObject(request);
HttpTransportSE ht=new HttpTransportSE(url);
ht.call(soapAction, envelope);//调用call方法,访问webservice
if(envelope.getResponse()!=null){
SoapPrimitive response=(SoapPrimitive)envelope.getResponse();
//如果要返回对象集合,在服务端可以将对象或集合序列化成json字符串返回,这边再反序列化成对象或集合
result=response.toString();//这里获得了webService的返回值
}
}catch(Exception e){
result=e.getMessage();
System.out.println("e="+result);
}
return result;
}
}