2010-07-20 74 views
1

我試圖讓一個WCF.net 4.0客戶端使用NuSOAP/0.7.2(1.94)Web服務。首先,Web服務不是基於當前的SOA標準,所以我必須創建一個自定義編碼器來處理ISO-8859-1消息編碼。當我得到的迴應,WCF拋出以下異常WCF .Net 4.0客戶端反序列化回覆消息體中的錯誤

「錯誤在反序列化的回覆消息的身體」

當尋找在SOAP身上,我看到<SOAP-ENV:Body>... stream ...</SOAP-ENV:Body>

有沒有人碰到這個錯誤來嗎?任何反饋或正確方向的一個點將非常感激。這是我的第一個WCF到「非」WCF服務。

ApplicationData 
TraceData 
<DataItem> 
<MessageLogTraceRecord Time="2010-07-14T19:14:36.4832868-07:00" Source="TransportReceive" Type="System.ServiceModel.Channels.StreamedMessage" xmlns="http://schemas.microsoft.com/2004/06/ServiceModel/Management/MessageTrace"> 
<HttpResponse> 
<StatusCode>OK</StatusCode> 
<StatusDescription>OK</StatusDescription> 
<WebHeaders> 
<X-SOAP-Server>NuSOAP/0.7.2 (1.94)</X-SOAP-Server> 
<Content-Encoding></Content-Encoding> 
<Content-Length>496</Content-Length> 
<Content-Type>text/xml; charset=ISO-8859-1</Content-Type> 
<Date>Thu, 15 Jul 2010 02:14:36 GMT</Date> 
<Server>Apache/2.0.54 (Unix) mod_ssl/2.0.54 OpenSSL/0.9.7a PHP/4.3.11</Server> 
<X-Powered-By>PHP/4.3.11</X-Powered-By> 
</WebHeaders> 
</HttpResponse> 
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="https://www.datatranswebedi.com/soapv2/"> 
<SOAP-ENV:Header></SOAP-ENV:Header> 
<SOAP-ENV:Body>... stream ...</SOAP-ENV:Body> 
</SOAP-ENV:Envelope> 
</MessageLogTraceRecord> 
</DataItem> 
</TraceData> 
</ApplicationData> 

由於提前, 布倫南

回答

2

原來有在反序列化的日期,因爲它以正確的格式是不是一個錯誤。我發現錯誤是在WCF客戶端啓用「詳細」調試模式。

System.InvalidCastException:無法將類型System.Xml.XmlNode []的對象分配給System.DateTime類型的對象。

傳統Web服務傳回「xsd:date」的日期和時間爲數據類型應爲「xsd:dateTime」的日期和時間。

爲了確認這是問題的原因,我向Web服務請求了兩條記錄,並在覆蓋消息ReadMessage()方法中操作XML,並更改了自動生成的代理類。這糾正了這個問題,我知道這不是最終的解決方案。在聯繫舊版Web服務的作者之前,有沒有人對Soap日期和日期時間格式有任何評論?

Maybe the following date is valid in Soap Version 1.1 with ISO-8859-1 encoding: 

<date xsi:type="xsd:date">2010-05-02 08:03:45</date> 

If it is, is this an issue using a custom encoder or was it really the date type/format in the soap body? Microsoft only accepted that date in the following format: 

<date xsi:type="xsd:dateTime">2010-05-02T08:03:45</date> 


    <customBinding> 
     <binding name="ISO8859Binding"> 
     <customTextMessageEncoding messageVersion="Soap11" encoding="ISO-8859-1" mediaType="text/xml" /> 
     <httpsTransport /> 
     </binding> 
     </customBinding> 

public override Message ReadMessage(Stream stream, int maxSizeOfHeaders, string contentType) 
{ 

    XmlReader reader = XmlReader.Create(stream); 
    XmlDocument doc = new XmlDocument(); 

    // Log to a file. 
    StreamWriter sw = new StreamWriter(@"C:\dump2.txt"); 

    doc.Load(reader); 
    doc.InnerXml = doc.InnerXml.Replace("xsd:date", "xsd:dateTime"); 
    doc.InnerXml = doc.InnerXml.Replace("2010-05-02 08:03:45", "2010-05-02T08:03:45"); 
    doc.InnerXml = doc.InnerXml.Replace("2010-05-02 12:38:06", "2010-05-02T12:38:06"); 

    sw.WriteLine(doc.InnerXml); 
    sw.Flush(); 
    sw.Close(); 

    byte[] buffer = System.Text.Encoding.Default.GetBytes(doc.InnerXml); 
    Stream test = new MemoryStream(buffer); 
    XmlReader reader2 = XmlReader.Create(test); 

    return Message.CreateMessage(reader2, maxSizeOfHeaders, this.MessageVersion); 

} 

再次感謝, 布倫南

相關問題