【发布时间】:2015-01-18 17:08:03
【问题描述】:
我在测试 Android 应用时遇到问题,尝试传递字符串参数,我希望返回参数的值,这是我的 WebService 代码:
[WebService(Namespace = "http://xxx.xxx.x.xxx:8080/root")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
[WebMethod]
public String SayHello(String name)
{
return name;
}
}
}
此 WebService 托管在我的本地 PC IIS 上 这是我的 Android 肥皂电话:
public class CallSoap {
// Lever one
public final String SOAP_SAY_HELLO = "http://xxx.xxx.x.xxx:8080/root/SayHello";
// Lever two operation
public final String SAY_HELLO_OPERATION = "SayHello";
// Lever four Soap target namespace
public final String WSDL_TARGET_NAMESPACE = "http://xxx.xxx.x.xxx:8080/root";
// Lever four Soap address
public final String SOAP_ADDRESS = "http://xxx.xxx.x.xxx:8080/Service1.asmx";
// Call say hello Method
public String getHello(String nameVal) {
String resp = new String();
SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,
SAY_HELLO_OPERATION);
request.addProperty("name", "Test");
SoapSerializationEnvelope envelop = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelop.dotNet = false;
envelop.setOutputSoapObject(request);
HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
Log.d("HTTP REQUEST", "HTTP REQUEST:\n" + httpTransport.requestDump);
Log.d("HTTP RESPONSE", "HTTP RESPONSE:\n" + httpTransport.responseDump);
Object response1 = new Object();
try {
httpTransport
.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
httpTransport.call(SOAP_SAY_HELLO, envelop);
if (envelop.bodyIn instanceof SoapObject) { // SoapObject = SUCCESS
SoapObject soapObject = (SoapObject) envelop.bodyIn;
response1 = envelop.getResponse();
} else if (envelop.bodyIn instanceof SoapFault) { // SoapFault =
// FAILURE
SoapFault soapFault = (SoapFault) envelop.bodyIn;
response1 = soapFault.getClass();
throw new Exception(soapFault.getMessage());
}
return resp;
} catch (Exception e) {
e.printStackTrace();
}
return resp;
}
}
我得到空值作为返回值,如果我检查肥皂信封,我可以在数据包中看到我的参数。我不知道发送的参数发生了什么。
请任何可以帮助我确定哪里出错的人,提前谢谢
【问题讨论】:
标签: java android .net web-services android-ksoap2