org.ksoap2.serialization.SoapSerializationEnvelope

大憨熊 提交于 2019-11-29 02:46:20

Go to Project/Properties/Java Build Path/Order and Export -- Make sure there's a check in front of Android Dependencies and the support library, if you use it.Mark all checkboxes and Click on Apply and clean the project.

((Button)findViewById(R.id.btnData)).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            NAMESPACE = "http://tempuri.org/";
            URL = "http://YOURURL/Service.asmx";
            SOAP_ACTION = "http://tempuri.org/SetLoginData";
            METHOD_NAME = "SetLoginData";
            EditText uname = (EditText) findViewById(R.id.editText1);
            EditText pwd = (EditText) findViewById(R.id.editText2);       

            String dataToSend="[{'UserID':uname.getText().toString() ,'Password':pwd.getText().toString() }]";

            SendData(dataToSend);
        }
    });
}

public void SendData(String data){

    Log.d(TAG, "SendData");
    Log.d(TAG, "URL   : "+URL);
    Log.d(TAG, "ACTION: "+SOAP_ACTION);

    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);

    Log.d(TAG, "Create");
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
    String dataToSend=data;
    Log.d(TAG, "dataToSend: "+dataToSend);

    PropertyInfo FromCurrency = new PropertyInfo();
    FromCurrency.setName("strInputData");
    FromCurrency.setValue(dataToSend);
    FromCurrency.setType(String.class);
    request.addProperty(FromCurrency);

    Log.d(TAG, "envelope");
    // Create the envelop.Envelop will be used to send the request
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

    envelope.implicitTypes=true;
    envelope.setAddAdornments(false);

    envelope.setOutputSoapObject(request);
    // Says that the soap webservice is a .Net service
    envelope.dotNet = true;

    Log.d(TAG, "URL");
    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

    try {
        Log.d(TAG, "call");
        androidHttpTransport.call(SOAP_ACTION, envelope);
        Log.d(TAG, "call1");
        SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
        Log.d(TAG,"response:"+ response.toString());
        TextView v = (TextView) findViewById(R.id.currency);
        v.setText("Retururn Responce" +  "= " + response.toString() ); 
    } catch (Exception e){
        e.printStackTrace();
    }
}

This webservice will take json data that's why i had passed data in json. so you have to check two three things that namespace is what, xml or json data , FromCurrency.setName("strInputData"); which is #c developer function argument name and internet permision requried.

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