我即将将应用程序移植到silverlight。到目前为止,我的客户端应用程序使用 netTcpBinding 与服务器通信。但是 Silverlight 不支持这一点,我发现他们建议改用自定义绑定。
我想知道我是否需要以关于安全性的特殊方式配置绑定。当客户端和服务器在同一台机器上运行但在不同机器上运行时,我的分布式应用程序运行良好。在这种情况下,我收到以下错误:
由于 EndpointDispatcher 的 ContractFilter 不匹配,接收方无法处理带有操作“ http://schemas.xmlsoap.org/ws/2005/02/rm/CreateSequence ”的消息。这可能是由于合同不匹配(发送方和接收方之间的操作不匹配)或发送方和接收方之间的绑定/安全不匹配。检查发送方和接收方是否具有相同的合同和相同的绑定(包括安全要求,例如消息、传输、无)。
我已经检查了合同和绑定(当切换到自定义绑定时会出现问题,而 netTcpBinding 可以正常工作)。该端口也在防火墙处启用。根据错误消息,我认为 WCF 可能假设了一些在客户端和服务器中不匹配的安全默认值。
服务器配置文件如下:
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<services>
<service behaviorConfiguration="MetaEnabledBehavior" name="MyService">
<host>
<baseAddresses>
<add baseAddress="http://MyIP:Port#/MyService"/>
</baseAddresses>
</host>
<endpoint address="custom"
binding="customBinding"
contract="MyService"
bindingConfiguration="binaryHttpBinding"
/>
</service>
</services>
<bindings>
<customBinding>
<binding name="binaryHttpBinding">
<binaryMessageEncoding />
<reliableSession ordered="true" inactivityTimeout="01:00:00"/>
<httpTransport />
</binding>
</customBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="MetaEnabledBehavior">
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<startup>
<supportedRuntime version="v2.0.50727"/>
</startup>
</configuration>
客户端配置是这样的:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<bindings>
<customBinding>
<binding name="default_binding">
<reliableSession ordered ="true" inactivityTimeout="01:00:00"/>
<binaryMessageEncoding maxReadPoolSize="64"
maxWritePoolSize="16"
maxSessionSize="2048">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</binaryMessageEncoding>
<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>
</bindings>
<client>
<endpoint address="http://MyIP:Port#/MyService/custom"
binding ="customBinding"
contract="MyService"
bindingConfiguration = "default_binding"
name="default_binding" />
</client>
</system.serviceModel>
</configuration>