1
package com.appu.pack;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import android.app.Activity;
import android.os.Bundle;

public class SampleFinalSapActivity extends Activity {
    /** Called when the activity is first created. */
    private final String NAMESPACE ="urn:sap-com:document:sap:soap:functions:mc-style";//this is my server namespace..
    private final String METHOD_NAME ="ZMATERIALS_GROUP_LIST";
    private final String SOAP_ACTION = NAMESPACE + "/" + METHOD_NAME;
    private final String URL ="http://************:8000/sap/bc/srt/wsdl/srvc_14DAE9C8D79F1EE197AD09B4D05C4345/wsdl11/allinone/ws_policy/document?sap-client=800&sap-user=*****&sap-password=******";
            @Override
        public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);

        Request.addProperty("Language", "d");

//这是wsdl文件中的属性之一

        System.out.println("the  Request is :::::"+Request);

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

        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

        System.out.println("TRANSPORT:"+androidHttpTransport);

 try
        {   

         androidHttpTransport.call(SOAP_ACTION, envelope);
        androidHttpTransport.debug = true;  //this is optional, use it if you don't want to use a packet sniffer to check what the sent message was (httpTransport.requestDump)

        //Object result = envelope.getResponse(); //getting response here

        //SoapPrimitive result1 = (SoapPrimitive)envelope.bodyIn;

       // System.out.println("Result : " + result1.toString());

     SoapObject response = (SoapObject)envelope.getResponse();

     System.out.println("RESPONSE:"+response);
        }
       catch(Exception e)
        {
            e.printStackTrace();
        }
    }
}

When I run this application  I got the exception:02-04 09:31:37.213: WARN/System.err(538): 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@4052d188)

我该如何解决?在这里我使用 Ksoap2.jar 来调用 webservices 有没有其他方法可以用 android 调用 sap soap webservices ?提前致谢...

4

1 回答 1

0

可能是代码中的一个小错误。我无法理解找到那个错误。我认为 URL 可能有问题。也许你可以参考我的答案。 Android Java 连接到在线数据库 工作代码张贴在那里。

于 2012-02-29T10:42:51.537 回答