使用 SAP WSDL WebService 时出现 XmlPullParserException

Posted

技术标签:

【中文标题】使用 SAP WSDL WebService 时出现 XmlPullParserException【英文标题】:XmlPullParserException when using SAP WSDL WebService 【发布时间】:2012-02-11 13:38:39 【问题描述】:

我正在拼命寻找 KSOAP2-android 中此 XmlPullParserException 的原因。 代码如下:

            String NAMESPACE = "urn:sap-com:document:sap:soap:functions:mc-style";
            String METHOD_NAME = "ZFanTestWs";
            String SOAP_ACTION = NAMESPACE + "/" + METHOD_NAME;
            String URL = "http://xxxx.xxx.xx:8000/sap/bc/srt/wsdl/bndg_xxx/wsdl11/allinone/standard/rpc?sap-client=xxx";

            SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

            PropertyInfo pi = new PropertyInfo();
            pi.setName("arg0");
            pi.setValue(42);
            pi.setType(PropertyInfo.INTEGER_CLASS);
            request.addProperty(pi);

            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.setOutputSoapObject(request);

            HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
            androidHttpTransport.debug = true;

            try
            
                androidHttpTransport.call(SOAP_ACTION, envelope);
                SoapPrimitive  resultsRequestSOAP = (SoapPrimitive) envelope.getResponse();
                result = resultsRequestSOAP.toString();
            
            catch(Exception e)
            
                e.printStackTrace();
            

异常发生在“androidHttpTransport.call(SOAP_ACTION,envelope);”上

HttpTransportSE 的 responDump 看起来和我生成的 WSDL 完全一样:

<wsdl:definitions targetNamespace="urn:sap-com:document:sap:soap:functions:mc-style"><wsdl:documentation><sidl:sidl/></wsdl:documentation><wsdl:types><xsd:schema attributeFormDefault="qualified" targetNamespace="urn:sap-com:document:sap:soap:functions:mc-style"><xsd:element name="ZFanTestWs"><xsd:complexType><xsd:sequence><xsd:element name="IvImporting" type="xsd:int"/></xsd:sequence></xsd:complexType></xsd:element><xsd:element name="ZFanTestWsResponse"><xsd:complexType><xsd:sequence><xsd:element name="EvExporting" type="xsd:int"/></xsd:sequence></xsd:complexType></xsd:element></xsd:schema></wsdl:types><wsdl:message name="ZFanTestWs"><wsdl:part name="parameters" element="tns:ZFanTestWs"/></wsdl:message><wsdl:message name="ZFanTestWsResponse"><wsdl:part name="parameter" element="tns:ZFanTestWsResponse"/></wsdl:message><wsdl:portType name="Z_FAN_TEST_WS"><wsdl:operation name="ZFanTestWs"><wsdl:input message="tns:ZFanTestWs"/><wsdl:output message="tns:ZFanTestWsResponse"/></wsdl:operation></wsdl:portType><wsdl:binding name="DEFAULT" type="tns:Z_FAN_TEST_WS"><soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/><wsdl:operation name="ZFanTestWs"><soap:operation soapAction="" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation></wsdl:binding><wsdl:service name="Z_FAN_TEST_WS"><wsdl:port name="DEFAULT" binding="tns:DEFAULT"><soap:address location="http://xxxx.xxx.xx:8000/sap/bc/srt/rfc/sap/z_fan_test_ws/xxx/z_fan_test_ws/default"/></wsdl:port></wsdl:service></wsdl:definitions>

它接受一个整数作为参数并返回它。 我的 NAMESPACE 和 SOAP_ACTION 字符串是否正确? 请分享你的想法。谢谢。

编辑:堆栈跟踪

01-17 10:12:11.090: W/System.err(555): org.xmlpull.v1.XmlPullParserException: expected: START_TAG http://schemas.xmlsoap.org/soap/envelope/Envelope (position:START_TAG <http://schemas.xmlsoap.org/wsdl/wsdl:definitions targetNamespace='urn:sap-com:document:sap:soap:functions:mc-style'>@1:429 in java.io.InputStreamReader@41076710) 
01-17 10:12:11.180: W/System.err(555):  at org.kxml2.io.KXmlParser.require(KXmlParser.java:2046)
01-17 10:12:11.190: W/System.err(555):  at org.ksoap2.SoapEnvelope.parse(SoapEnvelope.java:127)
01-17 10:12:11.210: W/System.err(555):  at org.ksoap2.transport.Transport.parseResponse(Transport.java:100)
01-17 10:12:11.221: W/System.err(555):  at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:195)
01-17 10:12:11.241: W/System.err(555):  at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:95)
01-17 10:12:11.260: W/System.err(555):  at webservice.test.WebServiceTestActivity$ServiceCall.doInBackground(WebServiceTestActivity.java:111)
01-17 10:12:11.281: W/System.err(555):  at webservice.test.WebServiceTestActivity$ServiceCall.doInBackground(WebServiceTestActivity.java:1)
01-17 10:12:11.292: W/System.err(555):  at android.os.AsyncTask$2.call(AsyncTask.java:264)
01-17 10:12:11.310: W/System.err(555):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
01-17 10:12:11.331: W/System.err(555):  at java.util.concurrent.FutureTask.run(FutureTask.java:137)
01-17 10:12:11.340: W/System.err(555):  at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
01-17 10:12:11.361: W/System.err(555):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
01-17 10:12:11.371: W/System.err(555):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
01-17 10:12:11.390: W/System.err(555):  at java.lang.Thread.run(Thread.java:856)

【问题讨论】:

异常的堆栈跟踪会告诉你.. 不幸的是,堆栈跟踪不是很有帮助 - 我已经在上面添加了它。它以某种方式在正确接收的 WSDL 中看不到开始标记。 你必须调试它,看看发生了什么。它可能出现故障或其他原因,并且全部混淆了。让我觉得你做错了什么的一件事是响应看起来像 wsdl.. 它不应该.. 【参考方案1】:

我已将 WSDL 文件的 URL 提供给 KSOAP,这是完全错误的。 您必须提供 SOAP 服务本身的 URL,它在 WSDL 文件中列出:

<soap:address location="http://xxxx.xxx.xx:8000/sap/bc/srt/rfc/sap/z_fan_test_ws/xxx/z_fan_test_ws/default"/>

字符串 SOAP_ACTION = NAMESPACE + "/" + METHOD_NAME; 在我的情况下工作正常。

感谢 Manfred Moser 和 JPriest 的回答!

【讨论】:

【参考方案2】:

你的soapaction应该是一个空字符串,如下:

String SOAP_ACTION = "";

【讨论】:

以上是关于使用 SAP WSDL WebService 时出现 XmlPullParserException的主要内容,如果未能解决你的问题,请参考以下文章

SAP 如何调用我的webservice?

SAP 如何调用我的webservice?

c++如何发布webservice

如何用soapui 测试sap webservice

webservice发布之后拒绝访问

php调用sap和.net的webservices接口