打开 WCF 服务主机连接时出错
Error while opening WCF service host connection
我无法打开我的 ServicHost 的连接。我最初使用它工作的 8080 端口 before.But 现在它不工作了。我发现我的 App.Conifg.Please 有一些错误(如下)让我知道错误在哪里。
这是一个简单的 EmployeeWCF 演示应用,带有 IEmployeeService 接口和 EmployeeService class。
App.Config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<system.serviceModel>
<services>
<service name="EmployeeWCFService.EmployeeService" behaviorConfiguration="mexBehaviour">
<endpoint name ="httpBind" address="EmployeeService" binding="basicHttpBinding" contract="EmployeeWCFService.IEmployeeService" ></endpoint>
<endpoint name ="netTcpBind" address="EmployeeService" binding="netHttpBinding" contract="EmployeeWCFService.IEmployeeService" ></endpoint>
<endpoint name="mexBind" address="mex" binding="mexHttpBinding" contract="IMetadataExchange" ></endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost:9090"/>
<add baseAddress="net.tcp://localhost:9093"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="mexBehaviour">
<serviceMetadata httpsGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
控制台代码:
class Program
{
static void Main(string[] args)
{
using (ServiceHost host = new ServiceHost(typeof(EmployeeWCFService.EmployeeService)))
{
host.Open();
Console.WriteLine("The connection host is opened at the time " + DateTime.Now);
Console.ReadLine();
}
}
}
我在打开 WCF Servicehost 时遇到的错误:
Additional information: A binding instance has already been associated to listen URI 'http://localhost:9090/EmployeeService'. If two endpoints want to share the same ListenUri, they must also share the same binding object instance. The two conflicting endpoints were either specified in AddServiceEndpoint() calls, in a config file, or a combination of AddServiceEndpoint() and config.
您的配置文件中可能有错字。第二个服务端点应该使用 NetTcpBinding 而不是 NetHttpBinding,这会导致两个服务端点具有相同的侦听 uri 地址。
如果问题仍然存在,请随时与我联系。
我无法打开我的 ServicHost 的连接。我最初使用它工作的 8080 端口 before.But 现在它不工作了。我发现我的 App.Conifg.Please 有一些错误(如下)让我知道错误在哪里。
这是一个简单的 EmployeeWCF 演示应用,带有 IEmployeeService 接口和 EmployeeService class。
App.Config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<system.serviceModel>
<services>
<service name="EmployeeWCFService.EmployeeService" behaviorConfiguration="mexBehaviour">
<endpoint name ="httpBind" address="EmployeeService" binding="basicHttpBinding" contract="EmployeeWCFService.IEmployeeService" ></endpoint>
<endpoint name ="netTcpBind" address="EmployeeService" binding="netHttpBinding" contract="EmployeeWCFService.IEmployeeService" ></endpoint>
<endpoint name="mexBind" address="mex" binding="mexHttpBinding" contract="IMetadataExchange" ></endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost:9090"/>
<add baseAddress="net.tcp://localhost:9093"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="mexBehaviour">
<serviceMetadata httpsGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
控制台代码:
class Program
{
static void Main(string[] args)
{
using (ServiceHost host = new ServiceHost(typeof(EmployeeWCFService.EmployeeService)))
{
host.Open();
Console.WriteLine("The connection host is opened at the time " + DateTime.Now);
Console.ReadLine();
}
}
}
我在打开 WCF Servicehost 时遇到的错误:
Additional information: A binding instance has already been associated to listen URI 'http://localhost:9090/EmployeeService'. If two endpoints want to share the same ListenUri, they must also share the same binding object instance. The two conflicting endpoints were either specified in AddServiceEndpoint() calls, in a config file, or a combination of AddServiceEndpoint() and config.
您的配置文件中可能有错字。第二个服务端点应该使用 NetTcpBinding 而不是 NetHttpBinding,这会导致两个服务端点具有相同的侦听 uri 地址。
如果问题仍然存在,请随时与我联系。