WCF - 发现该合同有多个终结点配置 - 错误

15

我们有一个运行良好的ASP.Net web应用程序和WCF。wcf服务作为Windows服务托管。一切都很好。然后我们进行了更改,使得服务契约将具有不同的名称空间(从Namespace1.IserviceContract更改为Namespace2.IserviceContract)。更改后,我们部署到服务器上,并在尝试实例化服务对象时遇到以下错误。

    System.InvalidOperationException: An endpoint configuration section for contract 'Namespace2.IserviceContract' could not be loaded because more than one endpoint configuration for that contract was found. Please indicate the preferred endpoint configuration section by name.

Generated: Fri, 06 Jul 2012 21:02:56 GMT


System.Web.HttpUnhandledException: Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.InvalidOperationException: An endpoint configuration section for contract 'Namespace2.IserviceContract' could not be loaded because more than one endpoint configuration for that contract was found. Please indicate the preferred endpoint configuration section by name.
   at System.ServiceModel.Description.ConfigLoader.LookupChannel(String configurationName, String contractName, Boolean wildcard)
   at System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors(ServiceEndpoint serviceEndpoint, String configurationName)
   at System.ServiceModel.ChannelFactory.ApplyConfiguration(String configurationName, Configuration configuration)
   at System.ServiceModel.ChannelFactory.ApplyConfiguration(String configurationName)
   at System.ServiceModel.ChannelFactory.InitializeEndpoint(String configurationName, EndpointAddress address)
   at System.ServiceModel.ChannelFactory`1..ctor(String endpointConfigurationName, EndpointAddress remoteAddress)
   at System.ServiceModel.EndpointTrait`1.CreateSimplexFactory()
   at System.ServiceModel.EndpointTrait`1.CreateChannelFactory()
   at System.ServiceModel.ClientBase`1.CreateChannelFactoryRef(EndpointTrait`1 endpointTrait)
   at System.ServiceModel.ClientBase`1.InitializeChannelFactoryRef()
   at System.ServiceModel.ClientBase`1..ctor()
   at TestApplication.ManagementWrapper.VerifyAuthentication(Int32 appId, String Token)
   at TestApplication.VerifyAuthentication(String tokenstring)

我们对此问题进行了研究,并发现如果在web.config文件中定义了两个客户端终结点,则会出现此类型的异常。然而,我们确定只定义了一个客户端终结点。此外,这个异常只出现在服务器上,本地运行正常。以下是我们的服务模型:

<system.serviceModel>
    <bindings>
      <netTcpBinding>
        <binding name="NetTcpBinding_Management" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions" hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="4194304" maxBufferSize="2147483647" maxConnections="10" maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="32768" maxNameTableCharCount="2147483647" />
          <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />
          <security mode="None" />
        </binding>
      </netTcpBinding>
    </bindings>
    <client>
      <endpoint address="net.tcp://servername:9010/Management/service/ManagementService" binding="netTcpBinding" bindingConfiguration="NetTcpBinding_Management" contract="Namespace2.IserviceContract" name="NetTcpBinding_IserviceContract" />
    </client>
  </system.serviceModel>

我们也尝试重新启动IIS和应用程序池,但仍然遇到相同的异常。


3
我想评论一下,WCF 是自从任何难以配置的事情以来最大的配置麻烦。 - The Muffin Man
代码中是否添加了端点? - Lieven Keersmaekers
@Lieven:不,没有通过代码添加端点。 - matmat
这可能会在未来帮助某人 - 即使您只有一个端点,您可能需要在代码中按名称引用它。 - Dan
4个回答

22

尝试搜索您的web.config文件,查找是否还有其他使用与ManagementService相同的网址。同时,在web.config文件中搜索任何引用旧命名空间(contract="Namespace1.IserviceContract")的内容。别忘了检查额外的.config文件。这个小问题曾经让我蒙受过损失。


3
无论使用什么协议,如basic、net.tcp或wshttp,该地址都应在web config文件中指定,从app.config文件的client部分中删除其他地址,在我的情况下,我将服务称为htp://machinename:700/test.svc,但是在客户端部分中有使用net.tcp和wshttp配置的地址,删除这些地址后,问题得到解决。

0
如果您的 web.config 中的所有内容都似乎正确无误,那么这个错误可能是由于同一服务器上的另一个应用程序引起的。我曾经为类似的问题烦恼了好几天。
在我的情况下,环境中有大量的 WCF 服务部署在单个网站下作为 Web 应用程序,在 IIS 中如下所示。
/Root Website
    /Service1
    /Service2
    /Service3
    /ServiceX

其中一个子服务错误地部署到了根网站的物理文件夹而不是它自己的物理文件夹。这个错误的部署包含了一个对所有服务都通用的客户端终结点定义,导致所有子服务都出现了问题。显然,父网站和子Web应用程序不能使用相同的客户端终结点。
从根网站中删除客户端终结点解决了我的问题。

0
请右键单击您的WCF服务的svc文件,然后单击“查看标记”。然后在那里修改命名空间。然后它应该可以正常工作了。

你的配置应该像这样:<service name="NameSpace.YourService"> <endpoint address="" binding="customBinding" bindingConfiguration="binaryHttp" contract="NameSpace.IYourService" /> <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration="" contract="IMetadataExchange" /> </service> - vinod8812

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接