android send data to a .net webservice

断了今生、忘了曾经 提交于 2019-12-25 05:45:08

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/16569807/android-send-data-to-a-net-webservice

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!