I am just a beginner in Android. I have to call a web service which I have develop in .NET from Android Studio. I found lots of code from google but still unable to figure out an issue
Here is my code I don't know if it's correct
public class MainActivity extends AppCompatActivity {
EditText LoginText;
String SOAP_ACTION = "https://mywebsite.com/ReadLogin";
String METHOD_NAME = "ReadLogin";
String namespace = "https://mywebsite.com/";
String url = "https://mywebsite/login.asmx";
public void checkLogin(View view) {
String login = LoginText.getText().toString();
RequestParams params = new RequestParams();
if (isNotNull(login)) {
//params.put("username", login);
call();
//invokeWS(params);
}
else {
Toast.makeText(getApplicationContext(), "Please enter valid email", Toast.LENGTH_LONG).show();
}
}
public void call()
{
try {
SoapObject request = new SoapObject(namespace, METHOD_NAME);
request.addProperty("username", "abc");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
//envelope.dotNet=true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(url);
androidHttpTransport.debug = true;
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
//final Vector<SoapObject> response = (Vector<SoapObject>)envelope.getResponse();
//final String str = response.toString();
//Object result = (Object)envelope.getResponse();
//String myResult = result.toString();
Toast.makeText(getApplicationContext(), resultsRequestSOAP.toString(), Toast.LENGTH_LONG).show();
} catch (Exception e) {
String mError =e.toString();
Toast.makeText(getApplicationContext(), mError, Toast.LENGTH_LONG).show();
}
}
Select all Open in new window
In catch exception I am getting an error like
android.os.NetworkOnMainTh
readExcept
ion
In AndroidManifest.xml I already added
<uses-permission android:name="android.perm
ission.INT
ERNET" />
and
android:usesCleartextTraff
ic="true"