WCF - 错误:传出消息的消息版本 (Soap12 (http://www.w3.org/2003/05/soap-envelope)

Posted

技术标签:

【中文标题】WCF - 错误:传出消息的消息版本 (Soap12 (http://www.w3.org/2003/05/soap-envelope)【英文标题】:WCF - Error: The message version of the outgoing message (Soap12 (http://www.w3.org/2003/05/soap-envelope) 【发布时间】:2012-11-24 05:02:59 【问题描述】:

1) 我在本地 IIS 5.1 上部署了 WCF 服务:

界面:

[OperationContract(Action = Service.RequestAction, ReplyAction = Service.ReplyAction)]
Message SetData(Message requestXml);

实施:

public const string ReplyAction = "http://localhost/AsurReceiveData/Message_ReplyAction";
public const string RequestAction = "http://localhost/AsurReceiveData/Message_RequestAction";

public Message SetData(Message requestXml)

    using (StreamWriter writer = File.CreateText(@"E:\Projekti\WCF\Parus\AsurReplicData\Parus\Body.xml"))
    
        writer.WriteLine(requestXml.ToString());
    
    Message response = Message.CreateMessage(MessageVersion.Default, ReplyAction, requestXml.ToString());

    return response;

Web.config:

<system.serviceModel>
  <serviceHostingEnvironment>
    <baseAddressPrefixFilters>
      <add prefix="http://localhost:80/"/>
    </baseAddressPrefixFilters>
  </serviceHostingEnvironment>
  <behaviors>
    <serviceBehaviors>
      <behavior name="Parus.ServiceBehavior">
        <serviceMetadata httpGetEnabled="true" httpGetUrl="http://localhost/AsurReceiveData/Service.svc"/>
        <serviceDebug includeExceptionDetailInFaults="true"/>
        <MyInspector />
      </behavior>
    </serviceBehaviors>
  </behaviors>
  <services>
    <service behaviorConfiguration="Parus.ServiceBehavior" name="Parus.Service">
      <endpoint address="http://localhost/AsurReceiveData/Service.svc" binding="basicHttpBinding" contract="Parus.IService">
      </endpoint>
      <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
    </service>
  </services>
  <extensions>
    <behaviorExtensions>
      <add name="MyInspector" type="Parus.MessageInspectorExtension, Parus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
    </behaviorExtensions>
  </extensions>
</system.serviceModel>

2) 客户端如下所示:

ServiceClient client = new ServiceClient();
string RequestAction = "http://localhost/AsurReceiveData/Message_RequestAction";
Message request = Message.CreateMessage(MessageVersion.Default, RequestAction, "Test message");
Message reply = client.SetData(request);

Web.config:

<binding name="BasicHttpBinding_IService" closeTimeout="00:01:00"
 openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
 allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
 maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
 messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
 useDefaultWebProxy="true">
 <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
  maxBytesPerRead="4096" maxNameTableCharCount="16384" />
 <security mode="None">
  <transport clientCredentialType="None" proxyCredentialType="None"
   realm="" />
  <message clientCredentialType="UserName" algorithmSuite="Default" />
 </security>
</binding>
<endpoint address="http://localhost/AsurReceiveData/Service.svc"
  binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService"
  contract="ServiceReference.IService" name="BasicHttpBinding_IService" />

当我运行客户端时,出现以下错误消息:

传出消息的消息版本(Soap12 (http://www.w3.org/2003/05/soap-envelope) Addressing10 (http://www.w3.org/2005/08/addressing))与编码器的不匹配(Soap11 (http://schemas.xmlsoap.org/soap/envelope/) AddressingNone (http://schemas.microsoft.com/ws/2005/05/addressing/none))。确保绑定配置为与消息相同的版本。

我怎样才能让它工作?

【问题讨论】:

【参考方案1】:

您的客户端和服务器之间的版本不匹配。确保您正在使用:

    消息版本相同 版本中的相同地址 相同的编码

【讨论】:

我知道,但是我应该在哪里设置它们,在 web.config 文件或代码中,我应该设置什么? 客户端出现错误消息,我已经尝试在消息创建方法中设置不同的选项,但没有任何帮助。

以上是关于WCF - 错误:传出消息的消息版本 (Soap12 (http://www.w3.org/2003/05/soap-envelope)的主要内容,如果未能解决你的问题,请参考以下文章

WCF 客户端异常:无法识别的消息版本

在“手动”发送肥皂消息时,我收到 WCF 的 AddressingNone 错误

如何将参数(id)传递给 WCF 中的消息检查器?

WCF 服务而不是 ASMX Web 服务?

“错误:消息文件太大”是传出端还是接收端的限制? [关闭]

传出 Skype 消息不适用于 Bot Framework