简体   繁体   English

如何使用KSoap在Android中使用WCF服务

[英]How to use KSoap for consuming WCF Services in Android

Using Ksoap2 for consuming WCf service in Android. 使用Ksoap2在Android中使用WCf服务。 getting this ErrorSoapFault - faultcode: 's:Client' faultstring: 'Invalid User Details.' 获取此ErrorSoapFault-错误代码:'s:Client'错误字符串:'无效的用户详细信息'。 faultactor: 'null' detail: org.kxml2.kdom.Node@41e72950 faultactor:“ null”详细信息:org.kxml2.kdom.Node@41e72950

try {

            SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

            request.addProperty("Username", "admin");
            request.addProperty("Password", "XXXXX");

            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.dotNet = false;
            envelope.xsd = SoapSerializationEnvelope.XSD;
            envelope.enc = SoapSerializationEnvelope.ENC;
            envelope.setOutputSoapObject(request);
            HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
            androidHttpTransport.call(SOAP_ACTION, envelope);
           // SoapPrimitive result = (SoapPrimitive)envelope.getResponse();
            SoapObject result = (SoapObject) envelope.getResponse();
            //to get the data
            String resultData = result.toString();
            // 0 is the first object of data


            sb.append(resultData + "\n");
        } catch (Exception e) {
            sb.append("Error:\n" + e.getMessage() + "\n");
        }

According to your errors, it seems that the client needs to provide the credential in order to be authenticated by the server. 根据您的错误,客户端似乎需要提供凭据才能由服务器进行身份验证。 How does the server authenticate the client in your web service? 服务器如何在您的Web服务中对客户端进行身份验证?
In General, we authenticate the client by the custom header, while the SOAPObject set the parameter value of the calling method. 通常,我们通过自定义标头对客户端进行身份验证,而SOAPObject设置调用方法的参数值。
You could refer to the following code to provide the identity information. 您可以参考以下代码来提供身份信息。

 public static void call(String methodName, SimpleArrayMap<String, Object> mapParams, ResponseCallBack reponseCallBack)
{
    HttpTransportSE transport = new HttpTransportSE(ENDPOINT);
    transport.debug = true;
    Element[] header = new Element[1];
    header[0] = new Element().createElement(NAMESPACE, ID_HEADERNAME);
    Element userName = new Element().createElement(NAMESPACE, ID_NAME_PARAM);
    userName.addChild(Node.TEXT, ID_NAME_VALUE);
    header[0].addChild(Node.ELEMENT, userName);
    Element password = new Element().createElement(NAMESPACE, ID_PASSWORD_PARAM);
    password.addChild(Node.TEXT, ID_PASSWORD_VALUE);
    header[0].addChild(Node.ELEMENT, password);

    SoapObject soapObject = new SoapObject(NAMESPACE, methodName);
    if (mapParams != null)
    {
        for (int index = 0; index < mapParams.size(); index++)
        {
            String key = mapParams.keyAt(index);
            Object value = mapParams.get(key);
            soapObject.addProperty(key, value);
        }
    }
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.headerOut = header;
    envelope.dotNet = isDotNet;
    envelope.bodyOut = soapObject;
    *****
   *****
     }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM