Cannot connect to WCF service on Android

I try to connect to the .NET WCF service in Android using kSOAP2 (v 2.1.2), but I always get a fatal exception when I try to make a service call. I am a little at a loss to track the error and cannot understand why this is happening. The code I'm using is below:

package org.example.android; import org.ksoap2.SoapEnvelope; import org.ksoap2.serialization.PropertyInfo; import org.ksoap2.serialization.SoapObject; import org.ksoap2.serialization.SoapSerializationEnvelope; import org.ksoap2.transport.HttpTransport; import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; public class ValidateUser extends Activity { private static final String SOAP_ACTION = "http://tempuri.org/mobile/ValidateUser"; private static final String METHOD_NAME = "ValidateUser"; private static final String NAMESPACE = "http://tempuri.org/mobile/"; private static final String URL = "http://192.168.1.2:8002/WebService.Mobile.svc"; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.validate_user); Intent intent = getIntent(); Bundle extras = intent.getExtras(); if (extras == null) { this.finish(); } String username = extras.getString("username"); String password = extras.getString("password"); Boolean validUser = false; try { SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); PropertyInfo uName = new PropertyInfo(); uName.name = "userName"; PropertyInfo pWord = new PropertyInfo(); pWord.name = "passWord"; request.addProperty(uName, username); request.addProperty(pWord, password); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); envelope.dotNet = true; envelope.setOutputSoapObject(request); HttpTransport androidHttpTransport = new HttpTransport(URL); androidHttpTransport.call(SOAP_ACTION, envelope); // error occurs here Integer userId = (Integer)envelope.getResponse(); validUser = (userId != 0); } catch (Exception ex) { } } private void exit () { this.finish(); } } 

EDIT: Delete old stack traces. Thus, the first problem was that the program could not open the connection due to missing methods or libraries due to the use of vanilla kSOAP2, and not a modified library for Android (kSOAP2-Android). The second problem is the problem with the settings. In the manifest, I did not add the following setting:

 <uses-permission android:name="android.permission.INTERNET" /> 

I am having a problem with XMLPullParser which I need to find out.

12-23 10: 58: 06.480: ERROR / SOCKETLOG (210): add_recv_stats recv 0

12-23 10: 58: 06.710: WARN / System.err (210): org.xmlpull.v1.XmlPullParserException: unexpected type (position: END_DOCUMENT null @ 1: 0 in java.io.InputStreamReader@433fb070 )

12-23 10: 58: 06.710: WARN / System.err (210): with org.kxml2.io.KXmlParser.exception (KXmlParser.java:243)

12-23 10: 58: 06.720: WARN / System.err (210): when org.kxml2.io.KXmlParser.nextTag (KXmlParser.java:1363)

12-23 10: 58: 06.720: WARN / System.err (210): at org.ksoap2.SoapEnvelope.parse (SoapEnvelope.java:126)

12-23 10: 58: 06.720: WARN / System.err (210): at org.ksoap2.transport.Transport.parseResponse (Transport.java:63)

12-23 10: 58: 06.720: WARN / System.err (210): at org.ksoap2.transport.HttpTransportSE.call (HttpTransportSE.java:100)

12-23 10: 58: 06.730: WARN / System.err (210): with org.example.android.ValidateUser.onCreate (ValidateUser.java:68)

12-23 10: 58: 06.730: WARN / System.err (210): with android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1122)

12-23 10: 58: 06.730: WARN / System.err (210): with android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2104)

12-23 10: 58: 06.730: WARN / System.err (210): with android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2157)

12-23 10: 58: 06.730: WARN / System.err (210): with android.app.ActivityThread.access $ 1800 (ActivityThread.java:112)

12-23 10: 58: 06.730: WARN / System.err (210): with android.app.ActivityThread $ H.handleMessage (ActivityThread.java:1581)

12-23 10: 58: 06.730: WARN / System.err (210): with android.os.Handler.dispatchMessage (Handler.java:88)

12-23 10: 58: 06.730: WARN / System.err (210): with android.os.Looper.loop (Looper.java:123)

12-23 10: 58: 06.730: WARN / System.err (210): with android.app.ActivityThread.main (ActivityThread.java:3739)

12-23 10: 58: 06.730: WARN / System.err (210): with java.lang.reflect.Method.invokeNative (Native Method)

12-23 10: 58: 06.730: WARN / System.err (210): with java.lang.reflect.Method.invoke (Method.java data15)

12-23 10: 58: 06.730: WARN / System.err (210): with com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:739)

12-23 10: 58: 06.730: WARN / System.err (210): when com.android.internal.os.ZygoteInit.main (ZygoteInit.java:497)

12-23 10: 58: 06.730: WARN / System.err (210): with dalvik.system.NativeStart.main (Native Method)

+4
source share
2 answers

Got this job. There were some problems mentioned above with the manifest file. In addition, the NAMESPACE, SOAP_ACTION, and URL parameters were incorrect. NAMESPACE required uri: to be pre-bound to it, just like SOAP_ACTION. The URL must have the specified endpoint instead of http://192.168.1.2:8002/WebService.Mobile.svc , it must be http://192.168.1.2:8002/WebService.Mobile.svc/Mobile . Connection problems are resolved, you just need to find out what happens with the data transfer.

0
source

Had the same problem and found this: http://code.google.com/p/ksoap2-android/issues/detail?id=35

See comments 15 and 17.

They suggest that you wrap the call on "androidHttpTransport.call (SOAP_ACTION, envelope)"; in try / catch and try again in case of error.

OR

Set the system property "http.keepAlive" to false.

Later in this release, someone suggests using "KeepAliveHttsTransport".

For me (I admit it is dirty) try / catch worked fine.

ERROR EDIT

+1
source