1

我想通过使用 ksoap2 来使用来自 andriod websevice 程序的肥皂网络服务。为此,我编写了以下代码。当我在 Android 模拟器中运行它时,我的 logcat 中没有得到响应。我的 web 服务返回类型结果是 XML 文件。

public class SoapWebservicesExampleActivity extends Activity {
    /** Called when the activity is first created. */
    final String NAMESPACE = "urn:sap-com:document:sap:soap:functions:mc-style";
    final String URL = "http://***********:8000/sap/bc/srt/wsdl/srvc_14DAE9C8D79F1EE196F1FC6C6518A345/wsdl11/allinone/ws_policy/document?sap-client=800&sap-user=*******&sap-password=*********";

//i am appending the Username and password as URL Parameters.

    final String METHOD_NAME = "Z_GET_CUST_GEN";
    final String SOAP_ACTION = "urn:sap-com:document:sap:soap:functions:mc-style/Z_GET_CUST_GEN";

// i am getting the method name tns from WSDL file.

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); // set up
        request.addProperty("Input", "1460");
        //  request.addProperty("Langu", "d");

//one property in the webservices 

        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); // put all required data into a soap
        envelope.dotNet = true;
        envelope.setOutputSoapObject(request);
        HttpTransportSE httpTransport = new HttpTransportSE(URL);
        httpTransport.debug = true;
        try {
            httpTransport.call(SOAP_ACTION, envelope);

// by using call method we can call the services

            SoapObject response = (SoapObject)envelope.getResponse();
            String str = response.getProperty(0).toString();
            System.out.println("theeeeeeeeeee"+str);

//printing the respose here

        }
        catch(SocketException ex){
            ex.printStackTrace();

        } catch (Exception e) {
               e.printStackTrace();
        }
    }

}

但这里的问题是我遇到了这个异常,我正在添加 ksoap2 jar 文件。

            05-29 15:37:54.403: WARN/System.err(383): 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:686 in java.io.InputStreamReader@40547218)
            05-29 15:37:54.403: WARN/System.err(383):     at org.kxml2.io.KXmlParser.exception(KXmlParser.java:273)
4

2 回答 2

0
    <soap:Header/> 
    <soap:Body> <urn:Z_GET_CUST_GEN> 
    <!--Optional:--> 
    <Input>1460</Input> 
    <!--Optional:-->
     <Langu>d</Langu> 
    <!--Optional:--> 
    <Max></Max> 

这是我的输入和输出 xml:

绑定网址

http://************:8000/sap/bc/srt/rfc/sap/z_customer_lookup1/800/z_customer_lookup1/z_customer_lookup1_bind

输出: -

<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope">
   <env:Header/>
   <env:Body>
      <n0:Z_GET_CUST_GENResponse xmlns:n0="urn:sap-com:document:sap:soap:functions:mc-style">
         <ZCustGen>
            <item>
               <Kunnr>0000001460</Kunnr>
               <Name1>C.A.S. Computer Application Systems</Name1>
               <City>Dresden</City>
               <Land>DE</Land>
               <Pstlz>01187</Pstlz>
            </item>
            <item>
               <Kunnr>0000027182</Kunnr>
               <Name1>Johnson Food Center Inc.</Name1>
               <City>Rochester</City>
               <Land>US</Land>
               <Pstlz>14608</Pstlz>
            </item>
            <item>
               <Kunnr>0000301046</Kunnr>
               <Name1>Second Source</Name1>
               <City>ROCHESTER</City>
               <Land>US</Land>
               <Pstlz>14602</Pstlz>
            </item>
         </ZCustGen>
      </n0:Z_GET_CUST_GENResponse>
   </env:Body>
</env:Envelope>

将输入设置为所有值(语言,最大值),然后您尝试。您是否尝试过。

于 2012-05-29T11:37:14.317 回答
0

这意味着您要添加的属性,即

request.addProperty("Input", "1460");

是不恰当的。请检查您正在调用的 Web 方法,并确保参数的数量、方法名称、参数的拼写(也包括大小写)正确。我一直收到此错误,这就是您修复它的方法。

(((也请分享您的网络方法。如果上述解决方案不起作用))

于 2012-05-29T11:24:21.363 回答