Android:如何在android中使用KSOAP将整数值传递给服务

时间:2011-06-02 05:19:16

标签: android

无法将整数值传递给服务请求。到达服务请求的值变为null 这是我的代码

private static final String METHOD_NAME =“GetPrivileges”;
private static final String NAMESPACE =“http://AuthorizationManagement.ServiceContracts/2007/01/”;

private static final String URL =“http://192.168.5.219/NTLS_Authorization/AuthorisationManager.asmx”;

final String SOAP_ACTION =“http://AuthorizationManagement.ServiceContracts/2007/01/GetPrivileges”;

    public void call(){         尝试{             SoapObject request = new SoapObject(NAMESPACE,METHOD_NAME);

        PropertyInfo pi=new PropertyInfo();
        pi.type=PropertyInfo.INTEGER_CLASS;
        pi.setName("RoleID");
        pi.setValue(3);
        pi.setNamespace(NAMESPACE);
        request.addProperty(pi);

        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.dotNet = true;
        envelope.setOutputSoapObject(request);


        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
        androidHttpTransport.call(SOAP_ACTION, envelope);

        Object result = envelope.getResponse();

        String resultData = result.toString();

2 个答案:

答案 0 :(得分:1)

 public void call(int number) 
        { 
            try 
            { 
                  String METHOD_NAME ="GetPrivileges";
                   String NAMESPACE = "http://AuthorizationManagement.ServiceContracts/2007/01/";
                   String URL ="http://192.168.5.219/NTLS_Authorization/AuthorisationManager.asmx";
                final String SOAP_ACTION ="http://AuthorizationManagement.ServiceContracts/2007/01/GetPrivileges";
                SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
                request.addProperty("RoleID",number);

                SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
                envelope.dotNet = true;
                envelope.setOutputSoapObject(request);


                AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL);
                androidHttpTransport.call(SOAP_ACTION, envelope);

                Object result = envelope.getResponse();

                String resultData = result.toString();
                Log.v("Result==>",resultData);
            }
            catch(Exception e)
            {
                e.printStackTrace();        
                }
        }

答案 1 :(得分:0)

只需添加此

即可
requestObject.addProperty("RoleID",3);

可以试试这段代码// 注意不要直接输入数字(在你的情况下为3)而是将其作为参数传递...

    final SoapObject requestObject = new SoapObject(Constants.NAMESPACE,METHOD_NAME );          
            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.dotNet = false;
            requestObject.addProperty("RoleID",number);

            envelope.setOutputSoapObject(requestObject);
            AndroidHttpTransport androidHttpTransport =new AndroidHttpTransport(Constants.URL);
            try
            {
                androidHttpTransport.call(Constants.SOAP_ACTION+METHOD_NAME, envelope);
                SoapObject response = (SoapObject)envelope.getResponse();
                Log.v("result",response.toString());
}
 catch(Exception e)
        {
            e.printStackTrace();

        }