WCF中的mexTcpBinding-IMetadataExchange错误 [英] mexTcpBinding in WCF - IMetadataExchange errors
问题描述
我想使WCF-over-TCP服务正常工作.我在修改自己的项目时遇到了一些问题,因此我想从VS2008中包含的基本" WCF模板开始.
I'm wanting to get a WCF-over-TCP service working. I was having some problems with modifying my own project, so I thought I'd start with the "base" WCF template included in VS2008.
这是最初的WCF App.config,当我运行该服务时,WCF测试客户端可以正常使用它:
Here is the initial WCF App.config and when I run the service the WCF Test Client can work with it fine:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
<system.serviceModel>
<services>
<service name="WcfTcpTest.Service1" behaviorConfiguration="WcfTcpTest.Service1Behavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8731/Design_Time_Addresses/WcfTcpTest/Service1/" />
</baseAddresses>
</host>
<endpoint address="" binding="wsHttpBinding" contract="WcfTcpTest.IService1">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WcfTcpTest.Service1Behavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="True" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
这很完美,完全没有问题.
This works perfectly, no issues at all.
我认为将其从HTTP更改为TCP是微不足道的:将绑定更改为它们的TCP等效项并删除httpGetEnabled serviceMetadata元素:
I figured changing it from HTTP to TCP would be trivial: change the bindings to their TCP equivalents and remove the httpGetEnabled serviceMetadata element:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
<system.serviceModel>
<services>
<service name="WcfTcpTest.Service1" behaviorConfiguration="WcfTcpTest.Service1Behavior">
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:1337/Service1/" />
</baseAddresses>
</host>
<endpoint address="" binding="netTcpBinding" contract="WcfTcpTest.IService1">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WcfTcpTest.Service1Behavior">
<serviceDebug includeExceptionDetailInFaults="True" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
但是当我运行它时,我在WCF服务主机中收到此错误:
But when I run this I get this error in the WCF Service Host:
System.InvalidOperationException:在服务Service1实施的合同列表中找不到合同名称"IMetadataExchange".将ServiceMetadataBehavior添加到配置文件或直接添加到ServiceHost,以启用对此合同的支持.
System.InvalidOperationException: The contract name 'IMetadataExchange' could not be found in the list of contracts implemented by the service Service1. Add a ServiceMetadataBehavior to the configuration file or to the ServiceHost directly to enable support for this contract.
我感觉到您无法使用TCP发送元数据,但这就是为什么要使用mexTcpBinding选项的原因?
I get the feeling that you can't send metadata using TCP, but that's the case why is there a mexTcpBinding option?
推荐答案
好吧,如果您希望拥有元数据-TCP或HTTP-您仍然需要包含serviceMetadata
行为!
Well, if you want to have metadata - TCP or HTTP - you still need to include the serviceMetadata
behavior!
<behaviors>
<serviceBehaviors>
<behavior name="WcfTcpTest.Service1Behavior">
<serviceDebug includeExceptionDetailInFaults="True" />
<serviceMetadata />
</behavior>
</serviceBehaviors>
</behaviors>
当然,您不能在其上带有"HttpGetEnabled"-但必须存在该行为本身才能启用元数据交换(并因此交换IMetadataExchange
合同).
Sure, you can't have a "HttpGetEnabled" on it - but the behavior itself must be present in order to enable exchange of metadata (and thus the IMetadataExchange
contract).
这篇关于WCF中的mexTcpBinding-IMetadataExchange错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!