【问题标题】:SOAP with ksoap2带有 ksoap2 的 SOAP
【发布时间】:2012-09-21 08:00:18
【问题描述】:

我在尝试从 android 调用 SOAP 服务时遇到问题。我谷歌,我发现我应该使用 ksoap2。所以我安装了那个库并得到了一些代码......

 String METHOD_NAME = "name";
      String SOAP_ACTION = "url/name";
     String NAMESPACE = "url";
      String URL = "url";
    //you can get these values from the wsdl file^

        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); //set up request
        request.addProperty("user", "user");
        request.addProperty("pass", "pass");
        //variable name, value. I got the variable name, from the wsdl file!
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); //put all required data into a soap envelope
        envelope.setOutputSoapObject(request);  //prepare request

        List<HeaderProperty> headerList = new ArrayList<HeaderProperty>();

        headerList.add(new HeaderProperty("Content-Type", "text/xml; charset=utf-8"));
        headerList.add(new HeaderProperty("SoapAction", "url/name"));                   
        HttpTransportSE httpTransport = new HttpTransportSE(URL);  
        httpTransport.debug = true; 
        try {
            httpTransport.call(SOAP_ACTION, envelope, headerList);
            SoapObject result=(SoapObject)envelope.getResponse();
        } catch (IOException e2) {
            // TODO Auto-generated catch block
            e2.printStackTrace();
        } catch (XmlPullParserException e2) {
            // TODO Auto-generated catch block
            e2.printStackTrace();
        }

它会在 XmlPullParserException e2 中引发异常,称为:

 org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope (position:START_TAG <html>@2:7 in java.io.InputStreamReader@406da6b8)

所以现在我不知道如何使它工作。我认为 android 的管理非常糟糕,因为在 iphone 上我可以在几分钟内让它工作。

顺便说一句,如果它可能有帮助,那就是应该使用的信封:

 <?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" +
            "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:tns=\"url\" " +
            "xmlns:soap=\"http://schemas.xmlsoap.org/wsdl/soap/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:wsdl=\"http://schemas.xmlsoap.org/wsdl/\" " +
            "xmlns:soap-enc=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" >" +
            "<SOAP-ENV:Body><mns:name xmlns:mns=\"url\" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">" +
            "<user xsi:type=\"xsd:string\">user</user>" +
            "<pass xsi:type=\"xsd:string\">pass</pass>" +
            "</mns:name></SOAP-ENV:Body></SOAP-ENV:Envelope>

任何帮助都会受到欢迎,因为我现在正试图让它工作很长一段时间......

也许有助于预期结果如下:

<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:MPListResponse><return xsi:type="xsd:string">[{"tip":"123456","stevilka":"123456789","key":"some value","zacetek":"01.05.2007","potek":"01.01.2018","axa":0},]</return></ns1:MPListResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>

这是我的 httptransport 请求:

 Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://www.w3.org/2003/05/soap-encoding" xmlns:v="http://www.w3.org/2003/05/soap-envelope"><v:Header /><v:Body><n0:name id="o0" c:root="1" xmlns:n0="url"><user i:type="d:string">user</user><pass i:type="d:string">pass</pass></n0:MPList></v:Body></v:Envelope>

【问题讨论】:

  • 您在 iPhone 开发中使用哪个 SOAP 库?
  • 我没有使用任何库,我使用 NSMutableURLRequest 和 NSURLConnection 和 NSXMLParser,但我看不出它对我有什么帮助...
  • 使用 SoapUI utilite 检查请求/响应格式。如果响应也不是 xml,则可能会出现 XmlPullParserException。也许服务器以错误响应 html。无论如何,请在调试中检查 androidHttpTransport.bodyOut。
  • 抱歉,它没有,它对我有帮助,我劫持了你的问题。但是,请参阅下面关于 wsdl2ksoap 使用的部分答案
  • 好的,它会返回一个 html,但为什么呢?响应如下: 404 Not Found未找到

    在此服务器上未找到请求的 URL /MobileWS。


    Apache/2.2.3 (CentOS) Server at url Port 443

标签: android soap ksoap2


【解决方案1】:

wsdl2ksoap 在这里可能会帮助您,如果您的 xml 响应不太长,则可以使用 java SAXparser。至少这是我成功采用的方法。

【讨论】:

    【解决方案2】:

    也许您的 SOAP Envelop 版本是错误的。尝试改变它。它对我有用。

            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-02-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多