Search code examples
androidsoapksoap2android-ksoap2

android send data to a .net webservice


I am trying to create a android app to send text and photos to .net webservice. I have functions in my webservice. one of them gets a dummy name(I created this to check if I can make a connection) and the other one is to insert some data into DB. I want to post my work to get help.

private final String NAMESPACE = "http://methodoor.com/";
//webservice is working, you can check it online
private final String URL = "http://servicing2.rotanet.com.tr/service.asmx";
private final String SOAP_ACTION = "http://methodoor.com/checkupservice/SendData";
private final String METHOD_NAME = "SendData";


       //Create request
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

    request.addProperty("containerId",1);
    .........
    .........           
    request.addProperty("sFileID","asd");
    request.addProperty("userId",1);

    //Create envelope
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet = true;
    //Set output SOAP object
    envelope.setOutputSoapObject(request);
    //Create HTTP call object
    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

    try {
        //Invole web service
        androidHttpTransport.call(SOAP_ACTION, envelope);
        //Get the response
        SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
        //Assign it to fahren static variable
        fahren = response.toString();
    } catch (Exception e) {

    }

My problem is, I am not sure if this is the correct way to pass data to webservice. it doesnt crash or gives any error message. It just doesnt insert into the DB


Solution

  • here you go..make sure to check spelling of each tag in your service, method name and path of your service..

    public SoapObject soap(String METHOD_NAME, String SOAP_ACTION, String NAMESPACE, String URL,String IP,String SERVICEPATH) throws IOException, XmlPullParserException 
     {
        abc.allowAllSSL();
        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); //set up request
        //request.addProperty("iTopN", "5"); //variable name, value. I got the   variable      name, from the wsdl file!
    
        request.addProperty("UserId", login);
        request.addProperty("Password", password);
    
    
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); // put all required data into a soap
        envelope.dotNet = true;
        envelope.setOutputSoapObject(request); // prepare request
        envelope.bodyOut = request;
          Log.d("ENVELOPE",""+"Coming3");
        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
        //androidHttpTransport.
        androidHttpTransport.call(SOAP_ACTION, envelope);
    
        Log.d("ENVELOPE",""+envelope.bodyIn);
        SoapObject result = (SoapObject) envelope.bodyIn; // get response
        Log.d("ENVELOPE",""+envelope.bodyIn);
        SoapObject responseBodyRaw,responseBody,tableRow;
        return result;
     }
    

    Here is parameter details

    private String NAMESPACE = "http://tempuri.org/";
    private String SOAP_ACTION = "http://tempuri.org/UserProfile";
    private String METHOD_NAME = "UserProfile";
    private String URL="https://172.17.60.15/HostingService/PhoneForService.asmx";
    //private String URL="https://172.19.2.250/testService/phone.asmx";
    private String SERVICEPATH="/HostingService/PhoneForService.asmx";
    

    I hope would be helpful for you