Android应用程序没有向Web服务发送值

时间:2017-03-02 06:24:46

标签: android web-services android-asynctask

我的webservicecall.java文件,其中包含调用服务器的代码

mail files

将该Web服务类称为asynctask中的另一个活动

  public class WebserviceCall {

/**
 * Variable Decleration................
 *
 */
String namespace = "http://bkagartala.technotripura.com/";
private String url = "http://bkagartala.technotripura.com/asha/WebService.asmx";

String SOAP_ACTION;
SoapObject request = null, objMessages = null;
SoapSerializationEnvelope envelope;
HttpTransportSE androidHttpTransport;
WebserviceCall() {
}


/**
 * Set Envelope
 */
protected void SetEnvelope() {

    try {

        // Creating SOAP envelope
        envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

        //You can comment that line if your web service is not .NET one.
        envelope.dotNet = true;

        envelope.setOutputSoapObject(request);
        androidHttpTransport = new HttpTransportSE(url);
         androidHttpTransport.debug = true;

    } catch (Exception e) {
        System.out.println("Soap Exception---->>>" + e.toString());
    }
}

// MethodName variable is define for which webservice function  will call
public String getchange_liveserver(String MethodName, String f_name)
{

    try {
        SOAP_ACTION = "http://tempuri.org/"+MethodName;

        //Adding values to request object
        request = new SoapObject(namespace, MethodName);

        //Adding Double value to request object
        PropertyInfo weightProp =new PropertyInfo();
        weightProp.setName("f_name");
        weightProp.setValue(f_name);

        weightProp.setType(String.class);

         request.addProperty(weightProp);

        //Adding String value to request object

        SetEnvelope();

        try {

            //SOAP calling webservice
            androidHttpTransport.call(SOAP_ACTION, envelope);

            //Got Webservice response
            String result = envelope.getResponse().toString();

            return result;

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

   }


/************************************/
 }

但主要问题是应用程序没有将该值发送给服务器....

网络服务代码

      aResponse = com.getchange_liveserver("soumya", "one");

1 个答案:

答案 0 :(得分:0)

将您的命名空间更改为tempuri.org我猜这是问题...我已经给出了简单的示例尝试并根据您的值进行替换...

我想问题出在您的NAMESPACE我可以在您的服务文件中看到tempuri.org

@Override
    protected Void doInBackground(Void... voids) {
        try {
            String NAMESPACE = "http://tempuri.org/";
            String METHOD_NAME = "Your Method Name";
            String SOAP_ACTION = NAMESPACE+METHOD_NAME;
            String URL = "http://bkagartala.technotripura.com/asha/WebService.asmx";
            SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

            request.addProperty("methodName", METHOD_NAME);

            request.addProperty("ModelNumber", VariableName You Want to Pass);

            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();

        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }