5

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

因此,当我使用soap 1.2 版本时,我收到错误消息“无法在没有有效操作参数的情况下处理请求。请提供有效的soap”我想知道我缺少什么以及我应该怎么做。

谢谢!

我已经做过的事情:

  • 添加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();
  }

 }

肥皂版本 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

肥皂版本 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
4

1 回答 1

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;

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

于 2012-06-12T10:49:47.657 回答