2012-02-13 97 views
0

我試圖從Android客戶端連接到Wcf Web服務器。我的客戶端正在使用簡單數據類型正常工作,但是當我嘗試使用複雜數據調用時,它提供了問題。每當我沒有做的info.setValue(憑證)發送憑據,這裏在ksoap請求中發送複雜類型到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(憑據)我得到eserilization錯誤。我已經浪費了大約2-3天的時間,請幫忙。

+0

作爲Json字符串還是以soap格式獲得響應?如果以Json字符串的形式獲得響應,那麼我們可以對請求進行硬編碼。 – 2012-02-13 16:01:08

+0

不,我發送請求以及以肥皂格式接收請求.. – user582776 2012-02-13 17:40:47

回答

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> 

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的,所以我使用,以便編組改變的開始標記和結束標籤,它爲我工作。