0

我正在尝试从 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 天,请帮忙。

4

1 回答 1

0

我得到了我的问题的解决方案。我注意到在 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>

安卓客户端

<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 中工作,所以我使用封送处理来更改开始标签和结束标签,它对我有用。

于 2012-02-16T13:27:46.060 回答