急,WebService交互出现异常

SimonYeung 2011-11-16 05:28:24
与WebService交互用的是ksoap2.jar开源包

WebService端:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace WebService
{
/// <summary>
/// Service1 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public bool ValidateUser(string strName, string strPwd)
{
if (strName.Equals("test") && strPwd.Equals("test"))
{
return true;
}
else
{
return false;
}
}
}
}



Android端访问WebService方法:将用户名("test"),密码("test")传到WebService端判断是否正确

private boolean CallWebService() {
String nameSpace = "http://tempuri.org/";
String methodName = "ValidateUser";
String url="192.16.168.82//Service1.asmx";
String SOAP_ACTION = nameSpace + methodName;
HttpTransportSE androidHttpTransport = null;
Object result = null;

boolean response = false;
SoapObject request = new SoapObject(nameSpace, methodName);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;

request.addProperty("userName", "test");
request.addProperty("userPwd", "test");

envelope.setOutputSoapObject(request);
envelope.bodyOut = request;
androidHttpTransport = new HttpTransportSE(url);

try {
androidHttpTransport.call(SOAP_ACTION, envelope);
result = (Object)envelope.getResponse(); //debug跟到这里,执行getResponse();完就抛异常
response = Boolean.parseBoolean(result.toString());
} catch(Exception e) {
e.printStackTrace();
}
return response;
}


P.S. IIS服务都正常,可以打开WebService端

弄了一下午没搞好,请高手指点,感谢。
...全文
180 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
A一剑飞鸿 2011-11-21
  • 打赏
  • 举报
回复
你是在本机上测试的吗?
如果是,建议在局域网里测试一下.
l13873666736 2011-11-21
  • 打赏
  • 举报
回复
SOAP2封装了一些东西,实在难整。
你BAIDU android 万能调用WEBSERVICE
这个原理简单,提交XML得到结果后解析XML
dontsaymiss 2011-11-18
  • 打赏
  • 举报
回复
HttpTransportSE androidHttpTransport = null;

为什么要 =null呢
glint 2011-11-16
  • 打赏
  • 举报
回复
建议不要用ksoap2,直接使用HttpURLConnection来访问WEBSERVICE,POST参数和返回值的处理可以参考ksoap
SimonYeung 2011-11-16
  • 打赏
  • 举报
回复
String url="192.16.168.82//Service1.asmx";

这里发帖手误,应该是

String url="192.16.168.82/Service1.asmx";

80,349

社区成员

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

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