今天在做WCF路由测试的时候,在配置好路由之后,一直提示"net.tcp://localhost/service/”不支持正在使用的 .Net 组帧模式。有关详细信息,请参见服务器日志。
我的路由是wsHttpBinding协定去路由两个netTcpBinding协定的WCF。
后来发现问题的原因在于,我的netTcpBinding的bindingConfiguration进行了设置,而在路由的时候没有进行相应的设置。
我得netTcpBinding主要配置
<behaviors> <serviceBehaviors> <behavior name="MyBehavior"> <serviceDebug includeExceptionDetailInFaults="true"/> </behavior> </serviceBehaviors> </behaviors> <bindings> <netTcpBinding> <binding name="TcpBinding" maxReceivedMessageSize="2147483647" transferMode="Streamed"> <readerQuotas maxDepth="64" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="16384"/> </binding> </netTcpBinding> </bindings> <services> <service name="CAwcftest.FilesService" behaviorConfiguration="MyBehavior"> <endpoint address="" binding="netTcpBinding" bindingConfiguration="TcpBinding" contract="FilesContract.Demo.IFilesService"/> <host> <baseAddresses> <add baseAddress="net.tcp://localhost:12251/service/"/> </baseAddresses> </host> </service> </services>
而在路由中采用代码生成配置如下:
ServiceEndpoint regularCalc = new ServiceEndpoint( ContractDescription.GetContract(typeof(IRequestReplyRouter)), new NetTcpBinding(), new EndpointAddress("net.tcp://localhost:12251/service/"));
后来修改为:
NetTcpBinding tc = new NetTcpBinding(); tc.MaxReceivedMessageSize = 2147483647; tc.TransferMode = TransferMode.Streamed; tc.Name = "TcpBinding"; ServiceEndpoint regularCalc = new ServiceEndpoint( ContractDescription.GetContract(typeof(IRequestReplyRouter)), tc, new EndpointAddress("net.tcp://192.168.100.32:12251/service/"));
之后恢复了正常。
总结:WCF服务端配置了绑定协议行为,在客户端引用时,就要进行相应的配置,不然就会导致"不支持正在使用的 .Net 组帧模式"错误!