使用kSoap2 Android客户端调用Magento的Web服务 [英] calling magento web service from android client using kSoap2
问题描述
我想从一个机器人client.which访问Magento的Web服务应该返回一个会话id.i甲肝已经完成使用Apache这个uing Java客户端,并很成功的调用方法。
怎样曾经与Android客户端的尝试,当我得到xmlpullparser例外:
10-24 15:25:44.409:WARN / System.err的(277):org.xmlpull.v1.XmlPullParserException:期望值START_TAG {http://www.w3.org/2001/12/soap-envelope}Envelope(位置:START_TAG @ 2:327 java.io.InputStreamReader@44ee2268)
i am trying to access a magento web service from a android client.which should return a session id.i hav already done this uing java client using apache and am successful in calling the method. How ever i am getting xmlpullparser exception when trying with android client as: 10-24 15:25:44.409: WARN/System.err(277): org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://www.w3.org/2001/12/soap-envelope}Envelope (position:START_TAG @2:327 in java.io.InputStreamReader@44ee2268)
嗯,这是从我试图访问登录方法我的WSDL文件:
well this is my wsdl file from which i am trying to access login method:
我的Java code:
my java code:
public class DeviceClientActivity extends Activity {
/** Called when the activity is first created. */
private static final String NAMESPACE = "urn:Magento";
private static final String URL = "http://xxx.xxx.xx.xxx/magento/index.php/api/v2_soap?wsdl";
private static final String METHOD_NAME = "login";
private static final String SOAP_ACTION ="urn:Mage_Api_Model_Server_V2_HandlerAction";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log
.d("WS",
"--------------------- Webservice Part Begins ---------------------");
Log.d("WS", "1. SoapObject Construction");
SoapObject objsoap=new SoapObject(NAMESPACE, METHOD_NAME);
objsoap.addProperty(用户名,alokxxxx);结果
objsoap.addProperty(apiKey,XXXXXX);结果
Log.d(WS,SOAP对象最终建设!!!);
objsoap.addProperty("username", "alokxxxx");
objsoap.addProperty("apiKey", "xxxxxx");
Log.d("WS", "Construction of SOAP Object End !!!");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
Log.d("WS", "2. Envelop Created");
envelope.setOutputSoapObject(objsoap);
Log.d("WS", "3. Request Into Envelop");
AndroidHttpTransport httpTransport = new AndroidHttpTransport(URL);
httpTransport.debug = true;
Log.d("WS", "5. Transport Level to True");
try {
httpTransport.call(SOAP_ACTION, envelope);
// 此错误警告/ System.err的(277):org.xmlpull.v1.XmlPullParserException:期望值START_TAG {http://www.w3.org/2001/12/soap-envelope}Envelope (位置:START_TAG @ 2:327 java.io.InputStreamReader@44ee2268)
Log.d("WS", "6. httpTransport.call");
if (envelope != null)
{
SoapObject loresponse = (SoapObject) envelope.getResponse();
SoapObject logObject = (SoapObject)loresponse.getProperty("sessionId");
Log.d("WS", "logObject: "+logObject);
}
else
{
Log.d("WS", "Response Envelop Error");
}
} catch (IOException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
}
}
}
登录您的帮助:
DEBUG / WS(333):--------------------- Webservice的部分开始------------------- - 结果
10-29 15:38:33.643:DEBUG / WS(333):1 SoapObject施工结果
10-29 15:38:33.673:DEBUG / WS(333):SOAP对象最终建设!结果
10-29 15:38:33.673:DEBUG / WS(333):2.外型创建
10-29 15:38:33.673:DEBUG / WS(333):3,请求放入信封结果
10-29 15:38:33.683:DEBUG / WS(333):5,传输层到Trueorg.ksoap2.transport.AndroidHttpTransport@44eeb200
10-29 15:38:33.683:DEBUG / TRY(333):在try块结果
10-29 15:38:34.903:WARN / System.err的(333):org.xmlpull.v1.XmlPullParserException:期望值START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope(位置:START_TAG @ 2:327 java.io.InputStreamReader@44efbe90)结果
什么建议吗?
谢谢。
log for your help:
DEBUG/WS(333): --------------------- Webservice Part Begins ---------------------
10-29 15:38:33.643: DEBUG/WS(333): 1. SoapObject Construction
10-29 15:38:33.673: DEBUG/WS(333): Construction of SOAP Object End !!!
10-29 15:38:33.673: DEBUG/WS(333): 2. Envelop Created
10-29 15:38:33.673: DEBUG/WS(333): 3. Request Into Envelop
10-29 15:38:33.683: DEBUG/WS(333): 5. Transport Level to Trueorg.ksoap2.transport.AndroidHttpTransport@44eeb200
10-29 15:38:33.683: DEBUG/Try(333): inside try block
10-29 15:38:34.903: WARN/System.err(333): org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope (position:START_TAG @2:327 in java.io.InputStreamReader@44efbe90)
any suggestion?
thanks.
推荐答案
这是我得到的登录工作。
诀窍是不要把?WSDL的网址
This is how i got the login to work. the trick is not to put the ?wsdl on the url
public boolean login()
{
try
{
SoapObject request = new SoapObject("http://schemas.xmlsoap.org/wsdl/","login");
request.addProperty("username",apiuid.getText().toString());
request.addProperty("apiKey",apipwd.getText().toString());
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=false;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(apiurl.getText().toString());
androidHttpTransport.call("http://schemas.xmlsoap.org/wsdl/login", envelope);
String result =(String)envelope.getResponse();
String URL = new String();
URL=apiurl.getText().toString();
Editor e = userDetails.edit();
e.putString("url", URL);
e.putString("uid", apiuid.getText().toString());
e.putString("pwd", apipwd.getText().toString());
e.putString("lastsession", result);
e.commit();
return true;
} catch(IOException e)
{alertbox("IO error",e.getMessage());return false;}
catch(XmlPullParserException e)
{alertbox("xml error",e.getMessage());return false;}
catch(Exception e)
{alertbox("error",e.getMessage());return false;}
}
这篇关于使用kSoap2 Android客户端调用Magento的Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!