WCF .Net 4.0客户端反序列化回复消息正文时出错
我正在尝试让 WCF .Net 4.0 客户端与 NuSOAP/0.7.2 (1.94) Web 服务一起使用。首先,Web 服务并不基于当前的 SOA 标准,因此我必须创建一个自定义编码器来处理 ISO-8859-1 消息编码。当我收到响应时,WCF 抛出以下异常
“反序列化回复消息正文时出错”
查看 SOAP 正文时,我看到
有人遇到过这个错误吗?任何反馈或正确方向的观点将不胜感激。这是我的第一个 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>
提前致谢, 布伦南
I am trying to get a WCF .Net 4.0 client to work with a NuSOAP/0.7.2 (1.94) Web Service. First thing, the web service is not based on current SOA standards so I had to create a custom encoder to handle the ISO-8859-1 message encoding. When I get the response, WCF throws the following exception
"Error in deserializing body of reply message"
When looking at the SOAP body, I see <SOAP-ENV:Body>... stream ...</SOAP-ENV:Body>
Has anyone come across this error? Any feedback or a point in the right direction would greatly be appreciated. This is my first WCF to "non" WCF service.
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>
Thanks in advance,
Brennan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
事实证明,反序列化日期时出现错误,因为它的格式不正确。我在 WCF 客户端中启用“详细”调试模式时发现了错误。
System.InvalidCastException:无法将 System.Xml.XmlNode[] 类型的对象分配给 System.DateTime 类型的对象。
旧版 Web 服务正在传回带有日期和时间的“xsd:date”,而数据类型应为“xsd:dateTime”。
为了确认这是问题的原因,我从 Web 服务请求了两条记录,并在覆盖 Message ReadMessage() 方法中操作了 XML,并更改了自动生成的代理类。这解决了问题,我知道这不是最终的解决方案。在我联系旧版 Web 服务的作者之前,有人对 Soap 日期和日期时间格式有任何意见吗?
再次感谢,
布伦南
It turns there was an error in deserializing the date because it was not in the proper format. I caught the error be enabling "Verbose" debug mode in the WCF client.
System.InvalidCastException: Cannot assign object of type System.Xml.XmlNode[] to an object of type System.DateTime.
The legacy web service was passing back "xsd:date" with a date and time when the data type should have been "xsd:dateTime".
To confirm this was the cause of the problem, I requested two records from the web service and manipulated the XML in the override Message ReadMessage() method and changed the auto generated proxy class. This corrected the problem and I know this not the final solution. Before I contact the author of the legacy web service, does anyone having any comments on the Soap date and dateTime format?
Thanks Again,
Brennan
我必须做同样的事情(针对另一个遗留类型的网络服务),我一开始就遇到了问题。
我发现了这篇优秀的博客文章WCF: Text Message Encoding and ISO-8859-1 Encoding 描述了为 WCF 实现自定义文本编码器时的一些陷阱 - 也许这对您有帮助?
另请查看之前关于同一主题的 Stackoverflow 问题:
从 WCF 调用使用 ISO-8859-1 编码的 Web 服务
I had to do the same thing (against another legacy type webservice) and I ran into issues at first.
I came across this excellent blog post WCF: Text Message Encoding and ISO-8859-1 Encoding which describes a few pitfalls when implementing a custom text encoder for WCF - maybe that'll be helpful to you?
Also check out a previous Stackoverflow question on the same topic:
Calling a webservice that uses ISO-8859-1 encoding from WCF