I'm having problems connecting to my web service. I've followed a couple of tutorials, especially http://drclawx.wordpress.com/2011/06/24/77/ and created a simple Wcf Hello World web service. I've downloaded the ksoap2 jar recommended on the site, but I had a couple of problems. I've downloaded a couple of later versions but the one that I can get to work is version 2.5.8. When I go to call my own web service I'm getting an XMLPullParserException. My web service will be used to check login credentials, it has a method called 'UploadLogin' which takes a username and password. The following is my code
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;
}
}
The error that I'm getting is the following. Can someone please help or suggest how I might go about fixing this issue.
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)
For anyone that's interested, the reason I was getting this error was because the messageEncoding was using MTOM, so I changed this to Text and it work - messageEncoding="Text"