【问题标题】:Sending complex type in ksoap request to Wcf web service将 ksoap 请求中的复杂类型发送到 Wcf Web 服务
【发布时间】:2012-02-13 15:51:47
【问题描述】:

我正在尝试从 android 客户端连接到 Wcf Web 服务。我的客户端在使用简单数据类型时运行良好,但是当我尝试使用复杂数据调用时,它会出现问题。 我已经这样做了:

 Credentials credentials=new Credentials();
  credentials.Username="xyz";
  credentials.Password="123";
  PropertyInfo info=new PropertyInfo();
  info.setName("credentials"); 
  info.setValue(credentials);               
  info.setNamespace(NAMESPACE);
  info.setType(new Credentials().getClass());
  request.addProperty(info);


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


                    HttpTransportSE httpTransport = new HttpTransportSE(URL);
                    Object response=null;
                    httpTransport.call(SOAP_ACTION, envelope);
                    response = envelope.getResponse();

每当我在不执行 info.setValue(credentials) 的情况下发送凭据时,我都可以将请求发送到服务器,但用户名和密码字段为空白。 如果我添加这个 info.setValue(credentials) 我会得到 eserilization 错误。我在这方面浪费了大约 2-3 天,请帮忙。

【问题讨论】:

  • 您收到的响应是 Json 字符串还是soap 格式?如果您收到的是Json 字符串响应,那么我们可以对请求进行硬编码。
  • 不,我正在发送请求以及以肥皂格式接收请求..

标签: android wcf android-ksoap2


【解决方案1】:

我得到了我的问题的解决方案。我注意到在 java 和 android 客户端中生成的请求。

Java 客户端

<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body><ns4:myfunction xmlns:ns4="http://tempuri.org/">
<ns4:newMobile>91----------</ns4:newMobile>
<ns4:countryId>1</ns4:countryId>
<ns4:credentials>
<ns2:Password xmlns:ns2="http://schemas.datacontract.org/2004/07/mycompanyWebService.Models">123</ns2:Password>
<ns2:Username xmlns:ns2="http://schemas.datacontract.org/2004/07/mycompanyWebService.Models">xyz</ns2:Username></ns4:credentials>
</ns4:myfunction>
</soapenv:Body>
</soapenv:Envelope>

Android 客户端

<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/"><v:Header /><v:Body>
<myfunction xmlns="http://tempuri.org/" id="o0" c:root="1">
<Mobile i:type="d:string">91----------</Mobile>
<countryId i:type="d:string">1</countryId>
<credentials i:type="d:anyType">
<Username i:type="d:string">hm.1</Username>
<Password i:type="d:string">123</Password></credentials>
</myfunction>
</v:Body>
</v:Envelope>

如果是 java 客户端,它可以工作,但不能在 android 中工作,所以我使用编组来更改开始标记和结束标记,它对我有用。

【讨论】:

    猜你喜欢
    • 2015-01-06
    • 1970-01-01
    • 2015-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-20
    • 1970-01-01
    相关资源
    最近更新 更多