使用 kSoap2 从 Android 客户端调用 magento Web 服务
我正在尝试从 android 客户端访问 magento web 服务。它应该返回一个会话 id。我已经使用 apache 使用 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}信封(position:START_TAG @2:327 in 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): ---------------------- Web 服务部分开始 ------------------- --
10-29 15:38:33.643: 调试/WS(333): 1. SoapObject 构造
10-29 15:38:33.673: DEBUG/WS(333): SOAP 对象的构造结束!!!
10-29 15:38:33.673:调试/WS(333):2.已创建信封 10-29 15:38:33.673: DEBUG/WS(333): 3. 请求进入信封
10-29 15:38:33.683:调试/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)
有什么建议吗? 谢谢。
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)
well this is my wsdl file from which i am trying to access login method:
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("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);
//error here 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)
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();
}
}
}
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这就是我登录工作的方式。
诀窍是不要将 ?wsdl 放在 url 上
This is how i got the login to work.
the trick is not to put the ?wsdl on the url