5

我正在尝试使用来自 android 的 Soap 调用 magento api,但我收到 XMLpullparser 异常。我正在使用 ksoap 库。我在 google 上搜索但我找不到任何解决方案。下面是我的代码..

1 import java.io.IOException;

2 import org.ksoap2.SoapEnvelope;
3 import org.ksoap2.serialization.SoapObject;
4 import org.ksoap2.serialization.SoapSerializationEnvelope;
5 import org.ksoap2.transport.AndroidHttpTransport;
6 import org.xmlpull.v1.XmlPullParserException;

7 import android.app.Activity;
8 import android.os.Bundle;
9 import android.util.Log;

10       public class MagentoSoapActivity extends Activity {
11         /** Called when the activity is first created. */

12      private static final String NAMESPACE = "urn:Magento";
13      private static final String Method_Name="login";
14      private static final String URL ="http://www,mymagento,com/api/soap/?wsdl=1";
15      private static final String SOAP_ACTION ="urn:Magento/login";

16 @Override
17 public void onCreate(Bundle savedInstanceState) {
18    super.onCreate(savedInstanceState);
19    setContentView(R.layout.main);
20    try {
21      SoapObject request = new SoapObject(NAMESPACE,Method_Name);

22        request.addProperty("username", "XXX");
23        request.addProperty("apiKey", "YYY");
24        SoapSerializationEnvelope envelopes = new SoapSerializationEnvelope(
25                SoapEnvelope.VER11);

26        envelopes.dotNet = false;
27        envelopes.xsd = SoapSerializationEnvelope.XSD;
28        envelopes.enc = SoapSerializationEnvelope.ENC;


29       envelopes.setOutputSoapObject(request);

30        AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL);
31        androidHttpTransport.debug =true;
32        androidHttpTransport.call(SOAP_ACTION, envelopes);//Getting the Exception here
33        Object result = envelopes.getResponse();

34        Log.d("sessionId", result.toString());

35        //making call to get list of customers

36        String sessionId = result.toString();

37        request = new SoapObject(NAMESPACE,"customerCustomerList");
38        request.addProperty("sessionId",sessionId );

39        envelopes.setOutputSoapObject(request);
40        androidHttpTransport.call(SOAP_ACTION, envelopes);

41        result = envelopes.getResponse();

42        Log.d("Customer List", result.toString());

43    } catch (Exception e) {
44        e.printStackTrace();
45    }
46 }
47 }

下面是堆栈跟踪:

org.xmlpull.v1.XmlPullParserException: expected: START_TAG   
{http://schemas.xmlsoap.org/soap/envelope/}Envelope (position:START_TAG <definitions   
name='Magento' targetNamespace='urn:Magento'>@4:50 in   
java.io.InputStreamReader@44f13f40) 

请帮助我,我对这个错误感到非常沮丧。提前致谢

4

4 回答 4

6

从对我有用的 URL 中删除后缀“?wsdl”。希望这对某人有帮助~

于 2012-12-04T08:25:56.080 回答
3

改变:

  private static final String URL ="http://indieswebs.in/demostore/api/soap/?wsdl=1";

  private static final String URL ="http://indieswebs.in/demostore/api/soap";

有关的:

于 2012-06-25T15:02:18.560 回答
1

我解决了我的问题。我更改了完整的代码,现在我使用 XMLRPC 而不是使用 SOAP。http://code.google.com/p/android-xmlrpc/ 上有 XmLRPC 库以及如何使用的示例这个图书馆。

这是如何在 android http://inchoo.net/mobile-development/android-development/parsing-the-xmlrpc-webservice-response-in-android/中解析此响应的链接

希望这可以帮助某人。

谢谢大家的回复。

于 2012-06-28T05:05:13.860 回答
1

我们在这类应用程序上做了很多工作,我们刚刚为 Android 和 iOS 开源了一个 SDK,以简化与 Magento 的 API 的连接。也许它可以帮助您进行开发或为您提供有关如何解决此问题的想法,因为我们还使用 ksoap 进行 SOAP 通信:http: //github.com/agilemonkeys/meets-android

于 2014-03-07T22:08:53.970 回答