C# 样本SOAP请求与#xA0;从服务器和客户端SOAP消息生成

C# 样本SOAP请求与#xA0;从服务器和客户端SOAP消息生成,c#,.net,xml,web-services,soap,C#,.net,Xml,Web Services,Soap,我正在开发一个应用程序,该应用程序需要来自客户端的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.w

我正在开发一个应用程序,该应用程序需要来自客户端的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
<?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>

 
   
串
   
 

您正在发送一个SOAp 1.1信封,而服务器需要SOAp 1.2。注意消息之间SOAP名称空间的差异。
编辑:至少,如果响应的前几个字节没有说“内部服务器错误”,我会这么说。我将在您的服务器实现上查找问题的原因。如果客户端消息无效,您可能会得到一些“错误的请求”响应。

问题在于xml标识行中的utf-16。通常,只需打开streamreader,然后打开ReadLine(),跳过这一行即可。然后使用流读取器并将其输入任何标准xml反序列化方法。