0

我在连接到我的 Web 服务时遇到问题。我遵循了一些教程,尤其是http://drclawx.wordpress.com/2011/06/24/77/并创建了一个简单的 Wcf Hello World Web 服务。我已经下载了网站上推荐的 ksoap2 jar,但我遇到了一些问题。我已经下载了几个更高的版本,但我可以开始工作的是 2.5.8 版。当我调用自己的 Web 服务时,我得到了 XMLPullParserException。我的 Web 服务将用于检查登录凭据,它有一个名为“UploadLogin”的方法,它接受用户名和密码。以下是我的代码

private class webService extends AsyncTask<String, Void, Void> {

    final String METHOD_NAME = "UploadLogin";
    final String NAMESPACE = "http://tempuri.org/";     
    final String URL = "http://10.0.2.2:52762/UploadService.svc";
    final String SOAP_ACTION = "http://tempuri.org/IUploadService/UploadLogin";

    // For the web service method: public String getLocations(String inputLocation))
    @Override
    protected Void doInBackground(String... entry) {

        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
        request.addProperty("username", "a");
        request.addProperty("password", "a");
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

        envelope.dotNet = true;
        envelope.setOutputSoapObject(request);
        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

        try {
            androidHttpTransport.call(SOAP_ACTION, envelope);

            Object response = (Object) envelope.getResponse();
            System.out.println("Login - " + response.toString());
        } 
        catch (Exception exception) {
            exception.printStackTrace();   
        }

        return null;
    } 
}

我得到的错误如下。有人可以帮助或建议我如何解决这个问题。

12-04 18:50:44.317: W/System.err(1704): org.xmlpull.v1.XmlPullParserException: Unexpected token (position:TEXT 
12-04 18:50:44.317: W/System.err(1704): --uuid:e537e5f2...@3:13 in java.io.InputStreamReader@41325c88) 
12-04 18:50:44.326: W/System.err(1704):     at org.kxml2.io.KXmlParser.next(KXmlParser.java:426)
12-04 18:50:44.336: W/System.err(1704):     at org.kxml2.io.KXmlParser.next(KXmlParser.java:310)
12-04 18:50:44.336: W/System.err(1704):     at org.kxml2.io.KXmlParser.nextTag(KXmlParser.java:2029)
12-04 18:50:44.346: W/System.err(1704):     at org.ksoap2.SoapEnvelope.parse(SoapEnvelope.java:126)
12-04 18:50:44.356: W/System.err(1704):     at org.ksoap2.transport.Transport.parseResponse(Transport.java:96)
12-04 18:50:44.356: W/System.err(1704):     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:189)
12-04 18:50:44.366: W/System.err(1704):     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:95)
12-04 18:50:44.376: W/System.err(1704):     at prometric.myitemwriter.ViewItemBankActivity$ws_MIR.doInBackground(ViewItemBankActivity.java:538)
12-04 18:50:44.376: W/System.err(1704):     at prometric.myitemwriter.ViewItemBankActivity$ws_MIR.doInBackground(ViewItemBankActivity.java:1)
12-04 18:50:44.396: W/System.err(1704):     at android.os.AsyncTask$2.call(AsyncTask.java:287)
12-04 18:50:44.426: W/System.err(1704):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
12-04 18:50:44.436: W/System.err(1704):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
12-04 18:50:44.516: W/System.err(1704):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
12-04 18:50:44.516: W/System.err(1704):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
12-04 18:50:44.526: W/System.err(1704):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
12-04 18:50:44.536: W/System.err(1704):     at java.lang.Thread.run(Thread.java:856)
4

3 回答 3

2
Instead of using kSOAP library, you can do it with built-in apache classes like HttpClient, HttpGet, HttpPost, etc.

For example: You want to send below JSON object:

{
   "email":"test@test.com",
   "password":"test"
}
then you can set your request object by using setEntity():

final String body = String.format("{\"email\":\"%s\",\"password\":\"%s\"}", s1, s2);

HttpClient client = new DefaultHttpClient();
HttpPost postMethod = new HttpPost(webServiceUrl);
postMethod.setEntity(new StringEntity(body, "utf-8"));
于 2014-01-29T06:53:38.100 回答
0

对于任何感兴趣的人,我收到此错误的原因是因为 messageEncoding 使用的是 MTOM,所以我将其更改为 Text 并且它可以工作 - messageEncoding="Text"

于 2012-12-05T17:48:00.983 回答
-1

在我的情况下,由于缺少所需的方法参数而发生错误:

    request.addProperty("cpf", "111111111");
于 2014-11-12T19:04:05.030 回答