无法理解 WCF MustUnderstand header

标签 wcf web-services c#-3.0 wcf-binding

我正在使用由我们的供应商之一开发的 Java Web 服务,我对它没有任何控制权。我编写了一个 WCF 路由器,客户端应用程序调用它,路由器将消息发送到 Java Web 服务并将数据返回给客户端。

我遇到的问题是,我能够从 WCF 路由器成功调用 Java Web 服务,但是,我收到以下异常。

路由器配置文件如下:

<customBinding>
    <binding name="SimpleWSPortBinding">
      <!--<reliableSession maxPendingChannels="4" maxRetryCount="8" ordered="true" />-->
      <!--<mtomMessageEncoding messageVersion ="Soap12WSAddressing10" ></mtomMessageEncoding>-->
      <textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
      messageVersion="Soap12WSAddressing10" writeEncoding="utf-8" />

      <httpTransport manualAddressing="false" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                                      allowCookies="false" authenticationScheme="Anonymous" bypassProxyOnLocal="true" keepAliveEnabled="true"
                                      maxBufferSize="65536" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false"/>
    </binding>
  </customBinding>

测试客户端配置文件
<customBinding>
            <binding name="DocumentRepository_Binding_Soap12">
              <!--<reliableSession maxPendingChannels="4" maxRetryCount="8" ordered="true" />-->
              <!--<mtomMessageEncoding messageVersion ="Soap12WSAddressing10" ></mtomMessageEncoding>-->

              <textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
                    messageVersion="Soap12WSAddressing10" writeEncoding="utf-8">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                </textMessageEncoding>

                <httpTransport manualAddressing="false" maxBufferPoolSize="524288"
                    maxReceivedMessageSize="65536" allowCookies="false" authenticationScheme="Anonymous"
                    bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                    keepAliveEnabled="true" maxBufferSize="65536" proxyAuthenticationScheme="Anonymous"
                    realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false"
                    useDefaultWebProxy="true" />
            </binding>
        </customBinding>

如果我使用 textMessageEncoding 我得到
<soap:Text xml:lang="en">MustUnderstand headers: [{http://www.w3.org/2005/08/addressing}To, {http://www.w3.org/2005/08/addressing}Action] are not understood.</soap:Text>     

如果我使用 mtomMessageEncoding 我得到
The server did not provide a meaningful reply; this might be caused by a contract mismatch, a premature session shutdown or an internal server error.

我的路由器类如下:
 [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple, AddressFilterMode = AddressFilterMode.Any, ValidateMustUnderstand = false)]
public class EmployeeService : IEmployeeService
{
    public System.ServiceModel.Channels.Message ProcessMessage(System.ServiceModel.Channels.Message requestMessage)
    {

        ChannelFactory<IEmployeeService> factory = new ChannelFactory<IEmployeeService>("client");

        factory.Endpoint.Behaviors.Add(new MustUnderstandBehavior(false));

        IEmployeeService proxy = factory.CreateChannel();

        Message responseMessage = proxy.ProcessMessage(requestMessage);

        return responseMessage;
    }
}

以上代码中ChannelFactory下的“client”在配置文件中定义为:
 <client>
  <endpoint address="http://JavaWS/EmployeeService" binding="wsHttpBinding"
      bindingConfiguration="wsHttp" contract="EmployeeService.IEmployeeService"
      name="client" behaviorConfiguration="clientBehavior">
    <headers>          
    </headers>
  </endpoint>
</client>

真的很感谢你的帮助。

提前致谢,
拉古

最佳答案

此问题已在 .NET 4.0 中使用 RoutingService 解决。

我仍然无法在 .NET 3.5 中解决这个问题

关于无法理解 WCF MustUnderstand header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2854092/

相关文章:

javascript - 从 Web 服务 (asmx) 页面引用 asp.net 页面上的字段

c# - 是否有更清晰的语法来将操作应用于序列的每个元素?

c# - 如何理解服务调用是 "Restful service call"还是 "standard wcf call"?

c# - HTTPERR 日志 : Request_Cancelled (while troubleshooting WCF service)

.net - 是否有 HTML 5 的 Web 套接字的 WCF 服务器实现?

php - Laravel 5.4-如何从服务器接收 JSON 数据并保存在数据库中

vb.net - 调用 Web 服务函数从 Windows 窗体返回列表(字符串)

c# - 转换数据 GridView

asp.net-mvc - .NET MVC : How to implement different page appearance per user?

wcf - 如何在服务端指定声明类型要求,以便客户端请求遵守它们?