WCF 服务提供错误"There was no endpoint listening..."



我有一个WPF/WCF应用程序,通过引用解决方案的"服务引用"文件夹中的.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>

此外,我在客户端有一个与上面的web.config相同的app.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,但没有帮助。

  • 服务器端应包含一个<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(,而不是实现该接口的具体类。

相关内容

最新更新