我的 .net webservice 显然正在运行 soap 1.2(通过检查 .wsdl)并且我一直在尝试访问 helloworld webservice 进行测试,但我遇到了错误。
顺便说一下,我试图通过模拟器来做到这一点。
因此,当我使用soap 1.2 版本时,出现“无法处理没有有效操作参数的请求。请提供有效的soap”的错误
我想知道我缺少什么以及我该怎么办。
谢谢!
我已经做过的事情:
我的代码:
private static final String NAMESPACE = "http://localhost/WebService/";
private static final String URL = "http://10.0.2.2:1672/Eventurous/WsEventurousMobile.asmx";
private static final String HelloWorld_SOAP_ACTION = "http://localhost/WebService/HelloWorld";
private static final String METHOD_NAME1 = "HelloWorld";
...
...
public static String GetHelloWorld() {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME1);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER12);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL,60000);
try {
androidHttpTransport.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
androidHttpTransport.call(HelloWorld_SOAP_ACTION, envelope);
SoapObject response = (SoapObject)envelope.getResponse();
String result = response.getProperty(0).toString();
return result;
} catch (Exception e) {
return e.toString();
}
}
Soap 版本 1.2 的错误
Code: soap:Sender, Reason: System.Web.Services.Protocols.SoapException: Unable to handle request without a valid action parameter. Please supply a valid soap action.
at System.Web.Services.Protocols.Soap12ServerProtocolHelper.RouteRequest()
at System.Web.Services.Protocols.SoapServerProtocol.RouteRequest(SoapServerMessage message)
at System.Web.Services.Protocols.SoapServerProtocol.Initialize()
at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean
Soap 版本 1.1 的错误
SoapFault - faultcode: 'soap:Client' faultstring: 'System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction: http://localhost/WebService/HelloWorld.
at System.Web.Services.Protocols.Soap11ServerProtocolHelper.RouteRequest()
at System.Web.Services.Protocols.SoapServerProtocol.RouteRequest(SoapServerMessage message)
at System.Web.Services.Protocols.SoapServerProtocol.Initialize()
at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)' faultactor: 'null' detail: org.kxml2.kdom.Node@413c9098
最佳答案
用SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
代替
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER12);
并删除这一行
androidHttpTransport.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
而不是
SoapObject response = (SoapObject)envelope.getResponse();
使用
SoapObject response = (SoapObject)envelope.bodyIn;
它将帮助您。如果仍然出现错误,请写信给我。