I'm quite new to Android
and WebServices
and at the moment I'm reading many info about Web Services, SOAP, etc.
I'm trying to write 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 don't know if this is normal) I'm also using local IIS with the following URL: http://localhost/HelloAndroid
.
Here is the code of my Web Service:
namespace HelloAndroid
{
[WebService(Namespace = "http://sample.com/")]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public string SayHello()
{
return "Hello, Android from .NET";
}
}
}
Android Activity:
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 = response.toString();
result.setText(resultValue);
}
catch (Exception e) {
result.setText(e.getMessage());
}
}
}
Thank you for your time