[英]calling magento web service from android client using kSoap2
我正在嘗試從android client。訪問一個magento Web服務,它應該返回一個會話ID。我已經使用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 }信封(位置:java.io.InputStreamReader@44ee2268中的START_TAG @ 2:327)
好吧,這是我嘗試訪問登錄方法的wsdl文件:
我的Java代碼:
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對象結束的構造!!”);
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);
// 錯誤在這里WARN / System.err(277):org.xmlpull.v1.XmlPullParserException:預期值:START_TAG { http://www.w3.org/2001/12/soap-envelope }信封(位置:START_TAG @ 2 :java.io.InputStreamReader@44ee2268中的327)
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):--------------------- Web服務部分開始-------------- -------
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/ }信封(位置:START_TAG @ .2:327 in java.io.InputStreamReader@44efbe90)
有什么建議嗎? 謝謝。
這就是我使登錄工作的方式。 訣竅是不要將?wsdl放在網址上
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;}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.