1

我正在尝试使用下面的 java 代码访问 SOAP 服务,我想在我的 Android 应用程序中使用该代码,但得到XmlPullParserException.

org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope (position:START_TAG <{http://www.w3.org/2003/05/soap-envelope}SOAP-ENV:Envelope>@1:114 in java.io.InputStreamReader@4a65e0)

我检查了所有与 XmlPullParserException 相关的标签,没有运气。请帮我纠正我的代码。

        import java.io.IOException;

        import org.ksoap2.SoapEnvelope;
        import org.ksoap2.SoapFault;
        import org.ksoap2.serialization.SoapObject;
        import org.ksoap2.serialization.SoapPrimitive;
        import org.ksoap2.serialization.SoapSerializationEnvelope;
        import org.ksoap2.transport.HttpTransportSE;
        import org.xmlpull.v1.XmlPullParserException;

            public class SoapClientClass {

                private static String SOAP_ACTION = "/Process Definition";       
                private static String METHOD_NAME = "EmployeeDetailsOperation";       
                private static String NAMESPACE = "http://InputMessageNamespace";       
                private static String URL ="http://10.213.45.05:5026/EmployeeService";    

                public static void main(String[] args)
                {
                    webserviceCall();    
                }

                private static void webserviceCall() {
                    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
                    // Pass parameters as Key value pair to URL 
                    request.addProperty("EmployeeId", "121"); 

                    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
                    envelope.setOutputSoapObject(request);
                    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
                    try {
                        androidHttpTransport.call(SOAP_ACTION, envelope);
                    } catch (IOException e) {
                        System.out.println("IOException");          
                        e.printStackTrace();
                    } catch (XmlPullParserException e) {
                        System.out.println("XmlPullParserException");
                        e.printStackTrace();
                    }
                    SoapPrimitive result = null;
                    try {
                        result = (SoapPrimitive)envelope.getResponse();
                    } catch (SoapFault e) {
                        System.out.println("SoapFault");
                        e.printStackTrace();
                    }

                    //to get the data         
                    String resultData = result.toString();
                    System.out.println("Result as String: \n"+resultData);

                }
            }
4

4 回答 4

1

我遇到了同样的问题,它与 SoapEnvelope 版本有关。

在这行代码中,当我将其更改为 VER11(您已经在使用)时,我使用的是 VER12,它起作用了

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

也许您可以测试其他版本,从 VER10 到 VER12 共有三个

于 2013-07-30T13:16:19.863 回答
0

根据以下代码行编辑您的代码...

private static String SOAP_ACTION = "http://InputMessageNamespace/Process Definition";       
                private static String METHOD_NAME = "EmployeeDetailsOperation";       
                private static String NAMESPACE = "http://InputMessageNamespace";
于 2012-04-09T09:11:25.557 回答
0

尝试在 URL 字符串的末尾添加“/”:

private static String URL ="http://10.213.45.05:5026/EmployeeService/";

而不是 SOAP_ACTION 使用 NAMESPACE + METHOD_NAME

于 2012-04-09T21:51:26.793 回答
0

我遇到了类似的问题,我想这个问题是因为我们用来连接网站的 URL。所以我通过像这样http://www.example.com/index.php/api/v2_soap/?wsdl/更改我的网站 URL 解决了这个问题 。

例子:

HttpTransportSE androidHttpTransport = new HttpTransportSE( http://www.example.com.com/index.php/api/v2_soap/?wsdl/ , 900000000); androidHttpTransport.call(" ", env);

于 2016-08-11T05:10:24.220 回答