【问题标题】:Mismatch between sample SOAP request generated from server and the client SOAP message从服务器生成的示例 SOAP 请求与客户端 SOAP 消息不匹配
【发布时间】: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">
            &lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-16&quot;?&gt;
            &lt;GetInfoRequest xmlns=&quot;http://www.sampleuri/XMLSchema" /&gt;
        </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


【解决方案1】:

您正在发送一个 SOAP 1.1 信封,而服务器正在等待 SOAP 1.2。请注意消息之间 SOAP 名称空间的不同。 编辑:至少,如果响应的前几个字节不会说“内部服务器错误”,我会这么说。我会在您的服务器实现中寻找问题的原因。如果客户端消息无效,您可能会收到一些“错误请求”响应。

【讨论】:

    猜你喜欢
    • 2011-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多