2

尝试从 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>
4

2 回答 2

0

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

        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
于 2013-11-15T19:34:48.410 回答
0

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

于 2012-09-21T08:38:44.100 回答