关于ksoap使用问题 急求

dragonmuou 2012-11-01 01:52:26

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???不知道问题的所在
...全文
154 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
nbaqqqq 2012-11-02
  • 打赏
  • 举报
回复
恩,又是WebService。
fire_fire_fire 2012-11-01
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 的回复:]

好了 原来权限弄错了
[/Quote]
无语。。。难道你没有加访问网络的权限???
dragonmuou 2012-11-01
  • 打赏
  • 举报
回复
好了 原来权限弄错了
fire_fire_fire 2012-11-01
  • 打赏
  • 举报
回复
这个原理我也不是很清楚,但是我这么写就可以得到值。我一直也是这么写的
dragonmuou 2012-11-01
  • 打赏
  • 举报
回复
你也没再我的代码进行改动啊 为什么你可以我却不行????只是我是用bodyin 你是用response 这应该没有什么影响吧啊??[Quote=引用 4 楼 的回复:]

返回值是0
[/Quote]
dragonmuou 2012-11-01
  • 打赏
  • 举报
回复
加个qq吧??可否 我的 358397190[Quote=引用 4 楼 的回复:]

返回值是0
[/Quote]
fire_fire_fire 2012-11-01
  • 打赏
  • 举报
回复
返回值是0
dragonmuou 2012-11-01
  • 打赏
  • 举报
回复
可以的话 加个qq吧 还有一些问题要问,我用response就报错这是怎么回事 所以我只能用bodyin[Quote=引用 1 楼 的回复:]

我调用了一下你的webService,没有问题呀。下面是我的全部代码,你参考一下。
可以的话就结贴吧
Java code

public class TestWebService extends Activity {

private static String NameSpace="http://tempuri.org/";//这个不要改
//http://116……
[/Quote]
dragonmuou 2012-11-01
  • 打赏
  • 举报
回复
你返回的值是什么???[Quote=引用 1 楼 的回复:]

我调用了一下你的webService,没有问题呀。下面是我的全部代码,你参考一下。
可以的话就结贴吧
Java code

public class TestWebService extends Activity {

private static String NameSpace="http://tempuri.org/";//这个不要改
//http://116……
[/Quote]
fire_fire_fire 2012-11-01
  • 打赏
  • 举报
回复
我调用了一下你的webService,没有问题呀。下面是我的全部代码,你参考一下。
可以的话就结贴吧

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;
}
}

80,350

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧