我正在尝试使用WCF(VS2010)构建两个Web服务。 一个webservice运行正常,但当我添加第二个webservice,然后我收到以下错误:
在列表中找不到合同名称“IMetadataExchange” 服务{0}实施的合同。添加一个 ServiceMetadataBehavior到配置文件或者 ServiceHost直接支持此合同。
第二个Web服务基本上是第一个Web服务的副本。所以我不知道为什么我得到这个错误以及如何解决这个问题。任何人都知道问题可能是什么?
这是我的App.config文件:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<services>
<service behaviorConfiguration="WcfEmguCV1.Service1Behavior" name="WcfEmguCV1.EvalService">
<endpoint address="" binding="wsHttpBinding" contract="WcfEmguCV1.IEvalService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8732/Design_Time_Addresses/WcfEmguCV1/Service1/" />
</baseAddresses>
</host>
</service>
<service name="WcfEmguCV1.Image">
<endpoint binding="wsHttpBinding" bindingConfiguration="" contract="WcfEmguCV1.IIMage">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" bindingConfiguration="" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8732/Design_Time_Addresses/WcfEmguCV1/Service2/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WcfEmguCV1.Service1Behavior">
<!-- To avoid disclosing metadata information,
set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="True"/>
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
<behavior name="WcfEmguCV1.Service2Behavior">
<!-- To avoid disclosing metadata information,
set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="True"/>
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
答案 0 :(得分:1)
我发现了我的问题。首先,我通过“编辑WCF配置”选项向App.config添加新数据。 (右键单击App.config文件,您应该看到该选项。)
由于第一个webservice配置默认已经存在,我必须添加一个新的。所以我试着输入完全相同的数据。但是有些东西不能通过这种方法添加。
因为当我仔细查看我的XML文件时,我注意到我错过了第二次网络服务:
<service behaviorConfiguration="WcfEmguCV1.Service1Behavior" ...>
所以我所要做的就是将它添加到'service'的第二个节点。
behaviorConfiguration = “WcfEmguCV1.Service2Behavior”