简体   繁体   中英

WCF: There was no channel actively listening

I created a WCF rest service in my ASP.NET (C#) application, and it seems to be working fine when I try to browse to it via web browser at the following localhost:81/ExternalServices/WS/SPP/REST/SPPService.svc

However, if I try to hit one of its methods, I get the below error message: localhost:81/ExternalServices/WS/SPP/REST/SPPService.svc/GetDetails

Message : There was no channel actively listening at ' http://MachineName.abc.local:81/ExternalServices/WS/SPP/REST/SPPService.svc/GetDetails '. This is often caused by an incorrect address URI. Ensure that the address to which the message is sent matches an address on which a service is listening.

Contract :

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();
    }
}

Implementation :

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";
        }
    }
}

The .SVC File (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>

A very helpful feature of WCF is the help page. It exposes all available services along with the correct URIs.

It can be located at: http://MachineName/Service.svc/help .

In my situation, it was: localhost:81/ExternalServices/WS/SPP/REST/SPPService.svc/help

This led me to see that the Web.Config file along with IIS were using HTTPS binding on port 82.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM