【发布时间】: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的类的名称。