Can´t connect to Web Service from Android

theomoHom

New Member
Hi I'm quite new to Android and Web Services and at the moment I'm reading many info about Web Services, SOAP, etc. I'm trying a Web Service example that just says Hello and it works in my browser but from my Android device/emulator doesn't work. I have set its ip to my PC ipv4 address and I have turned off the firewall and the antivirus.However if in the browser I try to connect to this IP it says 404. (I dont know if this is normal) I'm also using local IIS with the following URL: \[code\]http://localhost/HelloAndroid\[/code\] .Here is the code of my Web Service:\[code\]namespace HelloAndroid{ [WebService(Namespace = "http://sample.com/")] public class Service1 : System.Web.Services.WebService { [WebMethod] public string SayHello() { return "Hello, Android from .NET"; } }} \[/code\]Android Activity:\[code\]public class SoapTestActivity extends Activity { TextView result; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); result = (TextView)findViewById(R.id.result); final String NAMESPACE = "http://sample.com/"; final String METHOD_NAME = "SayHello"; final String SOAP_ACTION = "http://sample.com/SayHello"; final String URL = "http://192.168.1.35/HelloAndroid/Service1.asmx"; try { SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); envelope.dotNet = true; envelope.setOutputSoapObject(request); HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); androidHttpTransport.call(SOAP_ACTION, envelope); SoapPrimitive response = (SoapPrimitive)envelope.getResponse(); String resultValue = http://stackoverflow.com/questions/15712859/response.toString(); result.setText(resultValue); } catch (Exception e) { result.setText(e.getMessage()); } }}\[/code\]Thank you for your time
 
Back
Top