【问题标题】:WCF: There was no channel actively listeningWCF:没有频道主动收听
【发布时间】:2016-05-20 16:26:40
【问题描述】:

我在我的 ASP.NET (C#) 应用程序中创建了一个 WCF 休息服务,当我尝试通过以下网页浏览器浏览它时,它似乎工作正常 本地主机:81/ExternalServices/WS/SPP/REST/SPPService.svc

但是,如果我尝试使用其中一种方法,则会收到以下错误消息: localhost:81/ExternalServices/WS/SPP/REST/SPPService.svc/GetDetails

消息:在“http://MachineName.abc.local:81/ExternalServices/WS/SPP/REST/SPPService.svc/GetDetails”没有积极收听的频道。这通常是由不正确的地址 URI 引起的。确保消息发送到的地址与服务正在侦听的地址匹配。

合同

namespace ABC.WebApp.ExternalServices.WS.SPP.REST
{
    [ServiceContract]
    public interface ISPPService
    {
        [OperationContract]
        [WebInvoke(Method = "POST", UriTemplate = "GetProductionDetail")]
        string GetProductionDetail(Stream data);

        [OperationContract]
        [WebGet]
        string GetDetails();
    }
}

实施

namespace ABC.WebApp.ExternalServices.WS.SPP.REST
{
    [AspNetCompatibilityRequirements(RequirementsMode =  AspNetCompatibilityRequirementsMode.Allowed)]
    public class SPPService : ISPPService
    {
        public string GetProductionDetail(Stream xmlRequest)
        {
            return "hello";
        }

        public string GetDetails()
        {
            return "hello2";
        }
    }
}

.SVC 文件 (SPPService.svc)

<%@ ServiceHost Service = "ABC.WebApp.ExternalServices.WS.SPP.REST.SPPService" Language="C#" %>

Web.Config

<system.serviceModel>
<services>
  <service name="ABC.WebApp.ExternalServices.WS.Disb.Rest.DisbService" behaviorConfiguration="defaultBehaviour">
    <endpoint name="webHttpsBinding" address="" binding="webHttpBinding" contract="ABC.WebApp.ExternalServices.WS.Disb.Rest.IDisbService"
       behaviorConfiguration="webHttp" bindingConfiguration="webHttpTransportSecurity">
    </endpoint>
    <endpoint name="mexHttpsBinding" address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"></endpoint>
  </service>
  <service name="ABC.WebApp.ExternalServices.WS.SPP.REST.SPPService" behaviorConfiguration="defaultBehaviour">
    <endpoint name="webHttpsBinding" address="" binding="webHttpBinding" contract="ABC.WebApp.ExternalServices.WS.SPP.REST.ISPPService"
       behaviorConfiguration="webHttp" bindingConfiguration="webHttpTransportSecurity">
    </endpoint>
    <endpoint name="mexHttpsBinding" address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"></endpoint>
  </service>      
</services>
<bindings>
  <webHttpBinding>
    <binding name="webHttpTransportSecurity">
      <security mode="Transport"></security>
    </binding>
  </webHttpBinding>
</bindings>
<behaviors>
  <endpointBehaviors>
    <behavior name="webHttp">
      <webHttp helpEnabled="true" />
    </behavior>
  </endpointBehaviors>
  <serviceBehaviors>
    <behavior name="defaultBehaviour">
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
    <behavior name="">
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"></serviceHostingEnvironment>

【问题讨论】:

    标签: c# asp.net .net web-services wcf


    【解决方案1】:

    WCF 的一个非常有用的特性是帮助页面。它公开了所有可用的服务以及正确的 URI。

    它可以位于:http://MachineName/Service.svc/help

    在我的情况下,它是:localhost:81/ExternalServices/WS/SPP/REST/SPPService.svc/help

    这让我看到 Web.Config 文件和 IIS 在端口 82 上使用 HTTPS 绑定。

    【讨论】:

    • 不幸的是,WCF help 功能不能很好地与 WCF REST 配合使用。在我的例子中,我有一个 WCF 服务,它接受 URI 模板查询字符串参数和 WCF REST 支持的 Stream,但不是 WCF 的元数据/帮助提供程序(用于 SOAP,而不是 REST)所以它抱怨并拒绝提供有关系统中任何 WCF 服务的信息。呃(我很高兴 WCF 现在已经死了)。
    猜你喜欢
    • 1970-01-01
    • 2014-03-07
    • 2021-09-29
    • 1970-01-01
    • 2013-10-13
    • 1970-01-01
    • 2019-07-18
    • 1970-01-01
    • 2017-11-27
    相关资源
    最近更新 更多