WCF服务给出错误“没有端点监听...”

时间:2016-06-26 12:28:10

标签: web-services wcf deployment web-reference

我有一个WPF / WCF应用程序,我通过在我的解决方案的Service References文件夹中引用.asmx URL来使用外部Web服务。

在服务器端,我在web.config创建了条目,如下所示:

<binding name="ExtractService" 
     closeTimeout="00:01:00" openTimeout="00:01:00" 
     receiveTimeout="00:01:00" sendTimeout="00:10:00" 
     allowCookies="false" bypassProxyOnLocal="false" 
     hostNameComparisonMode="StrongWildcard" 
     maxBufferSize="2147483647" maxBufferPoolSize="524288" 
     maxReceivedMessageSize="2147483647"  
     messageEncoding="Text" textEncoding="utf-8" 
     transferMode="Buffered" useDefaultWebProxy="true">
    <readerQuotas maxDepth="32" maxStringContentLength="8192" 
           maxArrayLength="2147483647" maxBytesPerRead="4096" 
           maxNameTableCharCount="2147483647" />
    <security mode="Transport">
        <transport clientCredentialType="None" proxyCredentialType="None" realm="" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />
    </security>
</binding>
<client>
    <endpoint name="ExtractService" 
        address="https://example.com/DataExtractService.asmx" 
        binding="basicHttpBinding" bindingConfiguration="ExtractService" 
        contract="ExtractService" />
</client>

此外,我在客户端的app.config条目与上面的web.config相同。

当我在开发环境中运行它时,一切正常。也许是因为我的客户端和Web服务器(WCF)在同一台机器上。

但是当我在我的测试服务器上部署应用程序时,它开始给出以下错误。在这种情况下,客户端在我的机器上,服务器(WCF)在其他机器上。

  

消息:HandlingInstanceID:71a85aef-dbb0-4c28-9035-57f8b7526ee0
  发生并触发了类型'System.ServiceModel.EndpointNotFoundException'的异常。

     

https://example.com/DataExtractService.asmx没有可以接受该消息的端点。这通常是由错误的地址或SOAP操作引起的。有关更多详细信息,请参阅InnerException(如果存在)。

要解决此问题,我尝试在客户端的app.exe.config文件中复制相同的配置,但它不起作用。

我在哪里错过了客户端配置?我还复制了服务器bin文件夹中的app.config,但没有帮助。

1 个答案:

答案 0 :(得分:1)

  • 服务器方应包含一个<services>部分,用于定义此服务器上哪些端点可用的服务(必须至少一个 <service>子部分,定义至少一个端点,此服务可用于 - 也可能是多个)。

  • 客户端方应包含连接到其中一个可用端点的部分<client>

或简而言之:如果您的服务器端配置中有部分<services>,那么您的因此连接的任何端点,从而导致此错误。

所以你的服务器端配置应该是这样的:

<!-- Behavior is optional - maybe you need to define something, maybe not -->
<behaviors>
    <serviceBehaviors> 
        <behavior name="ExtractServiceBehavior">
          .....
        </behavior>
    </serviceBehaviors>
</behaviors>
<!-- Binding is the same as defined on the client -->
<binding name="ExtractService" ....
     ......
</binding>
<!-- Define all your services that you offer -->
<services>
    <service name="ExtractService"
             behaviorConfiguration="ExtractServiceBehavior">
        <endpoint name="ExtractService" 
            address="https://example.com/DataExtractService.asmx" 
            binding="basicHttpBinding" 
            bindingConfiguration="ExtractService" 
            contract="IExtractService" />
    </service>    
</services>    

另外:通常,您的合同应该是接口IExtractService) - 而不是实现该接口的具体类。

相关问题