XMLPull Parser Exception when calling Magento api using SOAP from Android
Asked Answered
S

4

5

I am trying to call magento api using Soap from android but I am getting XMLpullparser Exception.I am using ksoap library.I seached on google but i can't find any solution.Below is my code..

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 }

Below is stacktrace:

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) 

Please help me I am really depressed by this error. Thanks in advance

Shock answered 25/6, 2012 at 6:11 Comment(4)
what java version you are compiling on?Wahl
Your URL seems to have invalid spaces in between "indieswebs.in/demostore/api/soap? wsdl=1"Lifton
@vipul:Thanks for reply.I am using jdk7 but i don't think that is version problem.Shock
@Rajesh:Thanks for reply.Url is correct.The space problem was in posting but I edited it.You can check the response of webservice by given URL.Shock
S
1

I solved my problem.I changed the complete code and instead of using SOAP now I am using XMLRPC.There is XmLRPC library at http://code.google.com/p/android-xmlrpc/ and also the example of how to use this library.

This is the link for how to parse this response in android http://inchoo.net/mobile-development/android-development/parsing-the-xmlrpc-webservice-response-in-android/

Hope this helps someone.

Thanks everyone for your response.

Shock answered 28/6, 2012 at 5:5 Comment(6)
Hey...can you help me as i am also developing the same type of Application and getting the same error as you have describe above.I have gone through the above links but didn't understood anything..Please help meMeehan
hey buddy..having some doubts..please leave me a message when you are Online..byeMeehan
I want to confirm that can we use the Methods that are present in the Controllers of the Magento Site??Or else we have to make this formal Calls given by the XMLRPC api...and and...can we fetch the image of the product to display in Our Android Layouts..how to fetch them and how to save them??casn you teach me this much??Meehan
I think may be you can't directly use methods present in controllers of magento site.And you can fetch images using xmlrpc magentocommerce.com/api/soap/catalog/catalog.html. There is a method catalog_product_attribute_media.list.May it helpsShock
Ok..after fetching,how to Display them..i mean where to store that image and how to store them??Meehan
magentocommerce.com/api/soap/catalog/… showing this link I think it is returning Imageurl as String and You have to store this URL..Shock
R
6

remove the suffix "?wsdl" from URL it works for me. hope this helps someone~

Radiotransparent answered 4/12, 2012 at 8:25 Comment(0)
B
3

Change:

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

To

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

Related:

Bruiser answered 25/6, 2012 at 15:2 Comment(2)
Thanks for the reply.I tried your solution.It is working for getting session Id but after getting session Id at line 40 in my code at where I call "customerCustomerList" at that point I got the same error that "XMlpullParser Exception" but this time I got:org.xmlpull.v1.XmlPullParserException: expected: END_TAG {schemas.xmlsoap.org/soap/envelope}Body (position:END_TAG </{schemas.xmlsoap.org/soap/envelope}SOAP-ENV:Fault>@2:236 in java.io.InputStreamReader@44f07860)Shock
Hello,If I change the method name with "resources" then it is giving me response for api v1 but for api V2 I can't get response using call method.I had read at mage-page.net/2012/04/magento-api-v2-soap-demystified that I can't use call method for api V2 and I have to use method directly but I don't understand how to use method directly.If you understand or know anything then Please give me reply.ThanksShock
S
1

I solved my problem.I changed the complete code and instead of using SOAP now I am using XMLRPC.There is XmLRPC library at http://code.google.com/p/android-xmlrpc/ and also the example of how to use this library.

This is the link for how to parse this response in android http://inchoo.net/mobile-development/android-development/parsing-the-xmlrpc-webservice-response-in-android/

Hope this helps someone.

Thanks everyone for your response.

Shock answered 28/6, 2012 at 5:5 Comment(6)
Hey...can you help me as i am also developing the same type of Application and getting the same error as you have describe above.I have gone through the above links but didn't understood anything..Please help meMeehan
hey buddy..having some doubts..please leave me a message when you are Online..byeMeehan
I want to confirm that can we use the Methods that are present in the Controllers of the Magento Site??Or else we have to make this formal Calls given by the XMLRPC api...and and...can we fetch the image of the product to display in Our Android Layouts..how to fetch them and how to save them??casn you teach me this much??Meehan
I think may be you can't directly use methods present in controllers of magento site.And you can fetch images using xmlrpc magentocommerce.com/api/soap/catalog/catalog.html. There is a method catalog_product_attribute_media.list.May it helpsShock
Ok..after fetching,how to Display them..i mean where to store that image and how to store them??Meehan
magentocommerce.com/api/soap/catalog/… showing this link I think it is returning Imageurl as String and You have to store this URL..Shock
P
1

We've been working a lot on this kind of apps and we have just open sourced an SDK for Android and iOS to ease the connection with the Magento's APIs. Maybe it helps you with your development or give you ideas on how to resolve this issue, as we're also using ksoap for SOAP communications: http://github.com/agilemonkeys/meets-android

Photophobia answered 7/3, 2014 at 22:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.