【发布时间】:2017-05-23 16:47:14
【问题描述】:
我正在开发一个应用程序,该应用程序需要来自客户端的示例 SOAP 请求消息,该消息由 .svc 文件生成并具有以下 xml 结构:
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<GetInfo xmlns="http://sampleuri.org/">
<GetInfoRequest>string</GetInfoRequest>
</GetInfo>
</soap12:Body>
</soap12:Envelope
对应客户端的SOAP请求有如下xml结构:
<?xml version="1.0" encoding="utf-16"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<To s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://localhost:10000/WcfSmsStringService.svc</To>
<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://www.sampleuri/soap/GetInfo</Action>
</s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<GetInfoRequest xmlns="http://www.sampleuri/soap">
<?xml version="1.0" encoding="utf-16"?>
<GetInfoRequest xmlns="http://www.sampleuri/XMLSchema" />
</GetInfoRequest>
</s:Body>
</s:Envelope>
客户端收到以下错误:
出现异常 响应消息的内容类型 text/html 与绑定的内容类型不匹配 (text/xml; charset=utf-8)。如果使用自定义编码器,请确保正确实现 IsContentTypeSupported 方法。响应的前 75 个字节是:“页面无法显示,因为发生了内部服务器错误。”。
您能给我一个预约,这是解决此问题的最佳方法吗?
有没有办法更改服务器自动生成和预期的示例 SOAP 请求消息,或者有另一种更好的方法?
经过长时间的研究,我仍然没有找到解决这个问题的方法。
提前致谢!
【问题讨论】:
-
问题在于 xml 标识行中的 utf-16。通常只需打开一个流式阅读器,然后打开 ReadLine() 即可跳过这一行。然后使用流阅读器并输入任何标准的 xml 反序列化方法。
标签: c# .net xml web-services soap