soapobject如何传递属性?

时间:2015-08-20 09:01:31

标签: android web-services soap

我对此感到困惑。这是我的应用代码。

public void getUserInform(final String username,final String pwd) {
        new AsyncTask<Void, Void, String>() {

            @Override
            protected String doInBackground(Void... params) {
                String result = "";
                SoapObject rpc = new SoapObject(Config.SERVICEURL,
                        Config.METHODNAME);

                PropertyInfo p1 = new PropertyInfo();
                p1.setName("UserName".toString());
                p1.setValue("5100614".toString());
                p1.setType(String.class);

                PropertyInfo p2 = new PropertyInfo();
                p2.setName("pwd".toString());
                p2.setValue("E10ADC3949BA59ABBE56E057F20F883E".toString());
                p2.setType(String.class);



                rpc.addProperty(p1);
                rpc.addProperty(p2);

                System.out.println(rpc);
                System.out.println(rpc.getProperty(0).toString());
                System.out.println(rpc.getProperty(1).toString());

                SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                        SoapEnvelope.VER11);
                envelope.dotNet = true;
                envelope.setOutputSoapObject(rpc);
                HttpTransportSE transport = new HttpTransportSE(Config.ENDPOINT);
                try {
                    transport.call(Config.SOAPACTION, envelope);
                    SoapObject objects = (SoapObject) envelope.bodyIn;
                    System.out.println(objects);
                    result = objects.getProperty(0).toString();
                } catch (IOException e) {
                    e.printStackTrace();
                } catch (XmlPullParserException e) {
                    e.printStackTrace();
                }
                System.out.println(result);
                return result;
            }

此系统输出正确

GetUser{UserName=5100614; pwd=E10ADC3949BA59ABBE56E057F20F883E; }
5100614
E10ADC3949BA59ABBE56E057F20F883E
GetUserResponse{GetUserResult=ID or Password could not be null; }

但我发现我的webservice一直认为传递的参数是空的 我的网络服务在没有应用访问权限的情况下运行良好。

  [WebMethod]
        public string GetUser(string UserName,string pwd)
        {
            StreamWriter sw = File.AppendText("D:\\WebServiceLog.txt");
            string w = UserName+"///"+pwd;
            sw.Write(w);
            sw.Close();
            string result = "Unknown result!";
            if (UserName == null || pwd == null)
            {
                result = "ID or Password could not null";
            }
            else
            {
                UserService Uservcie = new UserService();
                List<UserModel> userList = Uservcie.GetUserAsList(UserName, pwd);

                if (userList.Count == 0)
                {
                    result = "can not find user";
                }
                if (userList.Count > 1)
                {
                    result = "Sorry,Not union user";
                }
                if (userList.Count == 1)
                {
                    result = userList[0].UserName.ToString() + '/' + userList[0].Name.ToString() + '/' + userList[0].Unit.ToString();
                }
            }
            return result;
        }

我不确定我的代码有什么问题。我只想使用soapobject访问带有属性的webservice。

1 个答案:

答案 0 :(得分:0)

rpc.addProperty("a", "myprop"); 

试试这个。