hello all
i try to connect to local host asmx webservice that insert data into local database from mobile application using android studio .
i received error
java.net.connectexception connection refused connect
can i connect to localhost webservice from android code , by the way my webservice work fine after run from visual studio
What I have tried:
this is my code in android studio :
=====class = =====
public class ContactResult {
public static int ErrorID ;
public static String ErrorMessage;
}
====== class 2 ==============
public class CallWebservice {
private final String NAMESPACE= "http://tempuri.org/";
private final String URL = "http://localhost:1844/AndroidWebService.asmx";
public void OpenAccount(String FullName , String Phone) {
final String METHOD_NAME = "OpenAccount";
final String SOAP_ACTION = "http://tempuri.org/OpenAccount";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("FullName", FullName);
request.addProperty("Phone", Phone);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
Object response = null;
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject result = (SoapObject) envelope.getResponse();
ContactResult.ErrorMessage = result.getProperty("ErrorMessage").toString();
ContactResult.ErrorID = Integer.parseInt(result.getProperty("ErrorID").toString());
}
catch (Exception e) {
e.printStackTrace();
}
}
======== this code inside mainActivity ======================
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void addclick(View view) {
final EditText txtname = (EditText)findViewById(R.id.txtname);
final EditText txtphone = (EditText)findViewById(R.id.txtphone);
Thread runt = new Thread(){
public void run(){
CallWebservice cweb = new CallWebservice();
cweb.OpenAccount(txtname.getText().toString() , txtphone.getText().toString());
}
};
runt.start();
try {
runt.join();
}
catch (Exception ex){}
}