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.
publicclassMainActivityextendsActivity {
EditText un,pw;
TextView tv;
Button test;
/** Called when the activity is first created. */@OverridepublicvoidonCreate(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(newOnClickListener(){
publicvoidonClick(View v) {
finalStringNAMESPACE="http://sparking.org/login";
finalStringMETHOD_NAME="login";
finalStringSOAP_ACTION="http://sparking.org/login";
finalStringURL="http://localhost:63734/service.asmx";
SoapObjectrequest=newSoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelopeenvelope=newSoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSEtransport=newHttpTransportSE(URL);
try {
transport.call(SOAP_ACTION, envelope);
SoapPrimitiveresultstring= (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.ThreadPolicypolicy=newStrictMode.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#"