对Java(Android)的SOAP请求

对Java(Android)的SOAP请求,android,soap,Android,Soap,我需要将这个soap请求转换为java(Android)。我正在使用ksoap2库来实现这一点,但我不断获得所需的错误身份验证。 我的java代码 SoapObject remoteUser = new SoapObject(NAMESPACE, "RemoteUser"); remoteUser.addProperty("UserLogin", "ws_admin"); remoteUser.addProperty(

我需要将这个soap请求转换为java(Android)。我正在使用ksoap2库来实现这一点,但我不断获得所需的错误身份验证。

我的java代码

     SoapObject remoteUser = new SoapObject(NAMESPACE, "RemoteUser");
                 remoteUser.addProperty("UserLogin", "ws_admin");
                remoteUser.addProperty("UserPassword", "Password1");

                SoapObject userContact = new SoapObject(NAMESPACE, "UserContact");
                userContact.addProperty("UserLogin", "sqa101");
                userContact.addProperty("UserPassword", "Password1");

                request.addSoapObject(remoteUser);
                request.addSoapObject(userContact);
                SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
                 envelope.dotNet = true;
                 envelope.setOutputSoapObject(request);
                 HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
                 androidHttpTransport.debug = true;
                 androidHttpTransport.call(SOAP_ACTION, envelope);
                 SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
                 webResponse = response.toString();
这是我得到的错误: 08-19 09:58:35.690:W/System.err(737):SoapFault-faultcode:'SOAP-ENV:Server'faultstring:'3001:未知用户试图执行消息类型UserAuthenticationRequest。需要身份验证。'faultactor:'null'详细信息:org.kxml2.kdom。Node@40585a08

任何帮助都将不胜感激

更新:我找到了答案。问题在于我使用的格式。下面的代码有效

     PropertyInfo remoteUser =new PropertyInfo();
                 remoteUser.setName("RemoteUser");
                     SoapObject login = new SoapObject();
                     login.addProperty("UserLogin", "admin");
                     login.addProperty("UserAuthenticator", "Password");
                 remoteUser.setValue(login);
                 remoteUser.setType(String.class);
                 request.addProperty(remoteUser);

                 PropertyInfo userContact =new PropertyInfo();
                 userContact.setName("UserContact");
                     SoapObject login2 = new SoapObject();
                     login2.addProperty("UserLogin", "username");
                     login2.addProperty("UserPassword", "Password");
                 userContact.setValue(login2);
                 userContact.setType(String.class);
                 request.addProperty(userContact);
试试这个

 public SoapObject GetMethodDataWithParameter(String URL , String SoapAction , 
                String WebService , String MethodName , 
                String ParameterName[] , String ParameterValue[])
        {
            WebServiceConfig objWSConfig = new WebServiceConfig(); 
            int ArryIndex = 0;

            SoapObject resultsRequestSOAP = null ;

            try
            {

                SoapObject request = new SoapObject(ws_Namespace,ws_Method);

                for(ArryIndex = 0 ; ArryIndex < ParameterName.length ; ArryIndex ++)
                {
                    PropertyInfo ParaObj = new PropertyInfo();
                    ParaObj.type = PropertyInfo.OBJECT_CLASS;
                    ParaObj.namespace = ws_Namespace;
                    ParaObj.setName(ParameterName[ArryIndex].toString());
                    ParaObj.setValue(ParameterValue[ArryIndex].toString());
                    request.addProperty(ParaObj);     
                }

                System.setProperty("http.keepAlive", "false"); 

                SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
                envelope.setOutputSoapObject(request);
                envelope.dotNet = true;
                //envelope.encodingStyle = SoapSerializationEnvelope.XSD;
                envelope.setAddAdornments(true);   

                HttpTransportSE androidHttpTransport = new HttpTransportSE(ws_URL);
                androidHttpTransport.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");

                try
                {
                    androidHttpTransport.call(ws_SOAPAction , envelope);
                }
                catch(SocketException se) 
                {
                    ERRORMSG = "Error in network connection." ;
                    Log.e(TAG, "Error in network connection.");
                    return resultsRequestSOAP;  
                }
                androidHttpTransport.debug = true;   

                resultsRequestSOAP = (SoapObject) envelope.bodyIn;  

            }
            catch (OutOfMemoryError e) 
            {
                e.printStackTrace();
                ERRORMSG = "Application running in out of memory.." ;
                Log.e(TAG , ERRORMSG);
                return resultsRequestSOAP;
            }
            catch(SocketException e) 
            {
                e.printStackTrace();
                ERRORMSG = "Error in network connection." ;
                Log.e(TAG, ERRORMSG);
                return resultsRequestSOAP;
            } 
            catch (Exception e)   
            {
                ERRORMSG = "Error while getting data." ;
                Log.e(TAG, ERRORMSG);
                e.printStackTrace();
            }
            return resultsRequestSOAP;  
        } 
公共SoapObject GetMethodDataWithParameter(字符串URL、字符串SoapAction、,
String WebService、String MethodName、,
字符串参数名称[],字符串参数值[])
{
WebServiceConfig objWSConfig=新的WebServiceConfig();
int ArryIndex=0;
SoapObject resultsRequestSOAP=null;
尝试
{
SoapObject请求=新的SoapObject(ws\u名称空间,ws\u方法);
对于(ArryIndex=0;ArryIndex
希望它能帮助你