Search code examples
c#androidksoap2

Android KSOAP with .Net Web Service


I have created web service using .Net C#. Now I am trying to access this from android app so I tried using KSOAP2.

This is my code.

final String NAMESPACE = "http://tempuri.org/";
final String METHOD_NAME = "HelloWorld";
final String SOAP_ACTION = "http://tempuri.org/HelloWorld";
final String URL = "http://localhost:61252/Service1.asmx"; 

new Thread() {

 public void run() {
                     SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
                     SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                     SoapEnvelope.VER11);
                     envelope.dotNet=true;
                     envelope.setOutputSoapObject(request);
                     HttpTransportSE  httpTransport = new HttpTransportSE(URL);
                     httpTransport.debug = true;
                     try {
                      httpTransport.call(SOAP_ACTION, envelope);
                      SoapObject result = (SoapObject) envelope.bodyIn;

                     }
                     catch (Exception e) {
                         // TODO: handle exception
                    }}}.start();

But in this line

httpTransport.call(SOAP_ACTION, envelope);

It is going into catch block and do not have any error message.

I also found so many questions regarding this but as i am new to this not able to find where i am going wrong.

Am I doing correct or is there any other method which i can use?


Solution

  •  SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);        
         SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
         envelope.setOutputSoapObject(request);
    
         HttpTransportSE ht = new HttpTransportSE(URL);
         ht.call(SOAP_ACTION, envelope);
         final  SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
         final String str = response.toString();
    

    use this for your reference. Hope this will help you.