android将数据发送到.net webservice

时间:2013-05-15 15:58:45

标签: android soap ksoap2 android-ksoap2

我正在尝试创建一个Android应用程序,以便将文本和照片发送到.net webservice。我的网络服务中有功能。其中一个获取一个虚拟名称(我创建它以检查是否可以建立连接)另一个是将一些数据插入到DB中。我想发布我的工作以获得帮助。

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) {

    }

我的问题是,我不确定这是否是将数据传递给webservice的正确方法。它没有崩溃或给出任何错误消息。它只是不插入数据库

1 个答案:

答案 0 :(得分:3)

这里你去..确保检查服务中每个标签的拼写,方法名称和服务路径..

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;
 }

这是参数详情

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";

我希望对你有所帮助