Skip to content Skip to sidebar Skip to footer

KSOAP2 Communication With Webservices C#

I am trying to send the login credentials from android user to a C# web service running in my local host through visual studio. I have used KSOAP2 for the SOAP communication and wa

Solution 1:

I guess the problem in your OnClickListener method, just try this.

public class MainActivity extends Activity {

    EditText un,pw;
    TextView tv;
    Button test;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button test=(Button) findViewById(R.id.login);
        un = (EditText) findViewById(R.id.et_un);
        pw = (EditText) findViewById(R.id.et_pw);


    test.setOnClickListener(new OnClickListener(){
    public void onClick(View v) {
    final String NAMESPACE = "http://sparking.org/login";
    final String METHOD_NAME = "login";
    final String SOAP_ACTION = "http://sparking.org/login";
    final String URL = "http://localhost:63734/service.asmx";

    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet = true;
    envelope.setOutputSoapObject(request);
    HttpTransportSE transport = new HttpTransportSE(URL);

  try {
    transport.call(SOAP_ACTION, envelope);
    SoapPrimitive resultstring = (SoapPrimitive)envelope.getResponse();

      }

    catch (Exception e)
    {
        e.printStackTrace();
    } 

                    } 
                }); 
 }
}

Solution 2:

That error is when you try to communicate through http from your main thread.

Just add those 2 lines before declaring the 'request' object:

StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);

Solution 3:

actually, localhost is emulator itself here because the code runs inside the emulator. so you should connect to 10.0.2.2. for more details see Android Emulator Networking and don't forget the network permissions in the manifest file


Post a Comment for "KSOAP2 Communication With Webservices C#"