WCF - EndpointNotFoundException

时间:2011-04-14 17:32:16

标签: wcf wcf-endpoint

我有以下情况: 项目A包含2个接口A,和B以及两个服务端点,EndpointA和EndpointB,每个端点都实现匹配接口。 我有一个单元测试项目,它使用Cassinini来测试服务。我使用我用svcutil生成的代理在单元测试中创建客户端对象。 这是我的单元测试项目中的app.config:

<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="basicHttp" closeTimeout="00:10:00" openTimeout="00:10:00"
      receiveTimeout="00:10:00" sendTimeout="00:10:00" allowCookies="false"
      bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
      maxBufferSize="5242880" maxBufferPoolSize="524288" maxReceivedMessageSize="5242880"
      messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
      useDefaultWebProxy="true">
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
        maxBytesPerRead="4096" maxNameTableCharCount="5242880" />
      <security mode="None">
        <transport clientCredentialType="None" proxyCredentialType="None"
          realm="" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />
      </security>
    </binding>
    <binding name="BasicHttpBinding_IAdministration" closeTimeout="00:01:00"
                        openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                        allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                        maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                        messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                        useDefaultWebProxy="true">
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
          maxBytesPerRead="4096" maxNameTableCharCount="16384" />
      <security mode="None">
        <transport clientCredentialType="None" proxyCredentialType="None"
            realm="" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />
      </security>
    </binding>
    <binding name="BasicHttpBinding_IRetrieval" closeTimeout="00:01:00"
        openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
        allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
        maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
        messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
        useDefaultWebProxy="true">
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
          maxBytesPerRead="4096" maxNameTableCharCount="16384" />
      <security mode="None">
        <transport clientCredentialType="None" proxyCredentialType="None"
            realm="" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />
      </security>
    </binding>
    <binding name="BasicHttpBinding_IModification" closeTimeout="00:01:00"
        openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
        allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
        maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
        messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
        useDefaultWebProxy="true">
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
          maxBytesPerRead="4096" maxNameTableCharCount="16384" />
      <security mode="None">
        <transport clientCredentialType="None" proxyCredentialType="None"
            realm="" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />
      </security>
    </binding>      
  </basicHttpBinding>
</bindings>
<client>      
  <endpoint address="http://localhost/MyServiceA.svc/MyServiceA"
      binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IRetrieval"
      contract="IRetrieval" name="BasicHttpBinding_IRetrieval" />
  <endpoint address="http://localhost/MyServiceB.svc/MyService"
      binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IModification"
      contract="IModification" name="BasicHttpBinding_IModification" />      
</client>

当我致电ServiceA时,它运行正常。但是,当我调用ServiceB时,收到以下错误消息:

  

测试方法MyMethod抛出异常:   System.ServiceModel.EndpointNotFoundException:由于EndpointDispatcher上的AddressFilter不匹配,无法在接收方处理带有To“http://localhost/MyServiceB.svc/MyServiceB”的消息。检查发件人和收件人的EndpointAddresses是否一致。

发生了什么事?感谢。

1 个答案:

答案 0 :(得分:0)

Cassini几乎从不在端口80处侦听。您需要找出Cassini侦听的端口并将其修复(使用项目属性/ web并将默认值更改为固定端口号)并更新端点:

 <endpoint address="http://localhost:<PORTNUMBER>/MyServiceB.svc/MyService"
  binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IModification"
  contract="IModification" name="BasicHttpBinding_IModification" />