服务器在进行Web服务连接时无法读取参数

时间:2015-03-23 16:45:44

标签: android asp.net web-services ksoap2

我使用下面的代码连接到.net webservice,我能够连接并从服务器获得不完整的响应。我正在添加userId has参数'1'具有string类型的值。问题是'服务器不能阅读请求中发送的所有参数'。我不确定我身边是否有问题。我已附上网络服务请求和回复以及我的代码。

enter image description here

和我的android连接代码

private class AsyncCallWS extends AsyncTask<String, Void, Void> {
        @Override
        protected Void doInBackground(String... params) {
            //Invoke webservice
        displayText=WebService.invokeHelloWorldWS(editText,"GetReminder");
        return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            //Set response
            tv.setText(displayText);
            //Make ProgressBar invisible
            pg.setVisibility(View.INVISIBLE);
        }

        @Override
        protected void onPreExecute() {
            //Make ProgressBar invisible
            pg.setVisibility(View.VISIBLE);
        }

        @Override
        protected void onProgressUpdate(Void... values) {
        }

    }

webservice在这里打电话。

public class WebService {
    //What is the Namespace of the Webservice ??
    private static String NAMESPACE = "http://tempuri.org";
    //Webservice URL
private static String URL = "http://1.3.44.5:8080/csmmobileapi/service.asmx";
    //SOAP Action URI ???
    private static String SOAP_ACTION = "http://tempuri.org/GetReminder";
    private  static final String TAG=null;
    public static String invokeHelloWorldWS(String name, String webMethName)  
{
        boolean result=false;
        String resTxt = null;
        // Create request
        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER11);
        SoapObject request = new SoapObject(NAMESPACE, webMethName);
        envelope.setOutputSoapObject(request);
        androidHttpTransport.debug=true;
        // Property which holds input parameters
        PropertyInfo sayHelloPI = new PropertyInfo();
        // Set Name
        sayHelloPI.setName("UserId");
        // Set Value
        sayHelloPI.setValue("1");
        // Set dataType
        sayHelloPI.setType(String.class);
        // Add the property to request object
       request.addProperty(sayHelloPI);
        //Set envelope as dotNet
        envelope.dotNet = true;
        try {
            // Invoke web service
            androidHttpTransport.call(SOAP_ACTION, envelope);
            // Get the response
            String response=androidHttpTransport.responseDump;
            Log.d("Result --- ", response.toString() );
           //tried with SoapObject and SoapPrimitive
            SoapObject obj=(SoapObject)envelope.getResponse();
            Log.d("Result --- ", obj);
            System.out.println("obj---->" + obj.toString());
}

1 个答案:

答案 0 :(得分:0)

做了一个非常愚蠢的错误,我在做了这么多试验后发现了错误的工作.., private static String NAMESPACE = "http://tempuri.org";已更改为private static String NAMESPACE = "http://tempuri.org/";,一切正常。