80,349
社区成员
发帖
与我相关
我的任务
分享
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;
}
}
}
}
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;
}