【问题标题】:There was no channel actively listening at .This is often caused by an incorrect address URI没有频道主动监听。这通常是由不正确的地址 URI 引起的
【发布时间】:2016-02-01 07:38:38
【问题描述】:

当我从 RestClient 调用 wcf 服务时出现错误:

[EndpointNotFoundException]: 'http://localhost/Test/TestService.svc/TestMethod' 处没有主动监听的频道。这通常是由不正确的地址 URI 引起的。确保消息发送到的地址与服务正在侦听的地址匹配。

<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0"/>
  </system.web> 
  <system.serviceModel>     
    <behaviors>
      <serviceBehaviors>
        <behavior name="mexBehaviour">
          <serviceMetadata httpGetEnabled="true"/>
          <useRequestHeadersForMetadataAddress>
            <defaultPorts>
              <add scheme="http" port="80" />
            </defaultPorts>
          </useRequestHeadersForMetadataAddress>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service name="TestService.TestService" behaviorConfiguration="mexBehaviour">
        <endpoint address="TestService" binding="basicHttpBinding" contract="TestService.ITestService"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange">

        </endpoint>
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost/Test/"/>
          </baseAddresses>
        </host>
      </service>
    </services>
  </system.serviceModel>
</configuration>

已经搜索了很多类似的问题,但没有解决,请帮助..

这里是服务代码:

 namespace TestService
{

    [ServiceContract]
        public interface ITestService 
        {
            [OperationContract, WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json)]
            string TestMethod();
        }
}

    namespace TestService
{
    public class TestService: ITestService 
        {
            public string TestMethod()
            {
                return "Hello";
            }
        }
}

【问题讨论】:

  • 基本上这个错误只表示你无法连接到服务器。例如防火墙阻止。不正确的配置。因此,localhost/Test 似乎不是您可以使用给定配置连接到的服务。那你能不能也提供一下服务器代码?
  • 没有防火墙,我正在本地系统中测试服务。服务器和客户端都在同一个系统上。当我从 IIS 浏览 svc 文件时,它按预期显示。
  • 是的,但它是如何编码的?似乎它没有运行或具有与您的客户端不兼容的配置。但是如果没有看到服务代码,就不可能知道这一点。
  • @BoasEnkler 请查看服务代码
  • 修复你的代码以显示实现ITestService的类的名称。

标签: wcf rest


【解决方案1】:

添加 UriTemplate = "Test/"

namespace TestService
    {

        [ServiceContract]
            public interface ITestService 
            {
                [OperationContract,WebInvoke(Method = "POST",ResponseFormat = WebMessageFormat.Json,UriTemplate = "Test/")] 
                string TestMethod();
            }
    }

配置:

    <configuration>
      <system.web>
        <compilation debug="true" targetFramework="4.0"/>
      </system.web> 
      <system.serviceModel>
    <bindings>
      <webHttpBinding>
        <binding name="webHttp"
         maxReceivedMessageSize="20000000" >
          <security mode="None">
            <transport clientCredentialType = "None"/>
          </security>
        </binding>
      </webHttpBinding>

    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="mexBehaviour">
          <serviceMetadata httpGetEnabled="true"/>
          <useRequestHeadersForMetadataAddress>
            <defaultPorts>
              <add scheme="http" port="80" />
            </defaultPorts>
          </useRequestHeadersForMetadataAddress>
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="web">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <services>
      <service name="TestService.TestService" behaviorConfiguration="mexBehaviour">
        <endpoint address="" binding="webHttpBinding" contract="TestService.ITestService" bindingConfiguration="webHttp" behaviorConfiguration="web"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange">

        </endpoint>

      </service>
    </services>
  </system.serviceModel>
    </configuration>

【讨论】:

    猜你喜欢
    • 2010-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多