微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

System.InvalidOperationException: '一个绑定实例已经关联到监听

如何解决System.InvalidOperationException: '一个绑定实例已经关联到监听

我刚刚为一个项目启动了 WCF,它显示以下异常,但是我发现了一些与此问题相关的问题,但我无法在我的代码中找到,我把我的代码在这里,请查看并提出建议我的代码的最佳解决方案。

    <system.serviceModel>
    <services>
      <service name="CompanyService.CompanyService" behaviorConfiguration="mexBehavIoUr">
        <endpoint address="CompanyService" binding="basicHttpBinding" contract="CompanyService.ICompanyPublicService"></endpoint>
        <endpoint address="CompanyService" binding="netHttpBinding" contract="CompanyService.ICompanyConfidentialService"></endpoint>
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8080/"/>
            <add baseAddress="net.tcp://localhost:8091/"/>
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="mexBehavIoUr">
          <serviceMetadata httpGetEnabled="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

以下是错误异常:

'A binding instance has already been associated to listen URI 'http://localhost:8080/CompanyService'. If two endpoints want to share the same ListenUri,they must also share the same binding object instance. The two conflicting endpoints were either specified in AddServiceEndpoint() calls,in a config file,or a combination of AddServiceEndpoint() and config. '

解决方法

需要修改端点地址的名称:

    <services>
      <service name="CompanyService.CompanyService" behaviorConfiguration="mexBehaviour">
        <endpoint address="CompanyService01" binding="basicHttpBinding" contract="CompanyService.ICompanyPublicService"></endpoint>
        <endpoint address="CompanyService02" binding="netHttpBinding" contract="CompanyService.ICompanyConfidentialService"></endpoint>
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8080/"/>
            <add baseAddress="net.tcp://localhost:8091/"/>
          </baseAddresses>
        </host>
      </service>
    </services>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。