soap 1.2 android请提供有效的肥皂动作

时间:2012-06-06 08:04:47

标签: android web-services soap ksoap2

我的.net webservice显然正在运行soap 1.2(通过检查.wsdl)并且我一直试图访问helloworld webservice进行测试但我遇到了错误。 我顺便试图通过模拟器做到这一点。

因此,当我使用soap 1.2版本时,我收到的错误是“无法处理没有有效操作参数的请求。请提供有效的肥皂” 我想知道我错过了什么,我该怎么做。

谢谢!

我已经完成的事情:

  • 添加Android使用互联网的权限
  • 从Soap版本1.1和1.2更改
  • 从SoapObject更改为Object(适用于soap 1.1和1.2)
  • 用于模拟器的10.0.2.2
  • 检查地址和方法名称中的拼写错误

我的代码:

 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

1 个答案:

答案 0 :(得分:0)

使用 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;

它会帮助你。如果仍然出现错误,请写信给我。