2009-10-26 89 views
2

我正在为现有的Windows服务进程构建WCF服务接口。 WCF接口的目的是提供一个“命令通道”来实现Windows服务的管理功能。定义了几种OperationContract方法,旨在从服务小程序的开始/停止/暂停功能之外提取信息并控制Windows服务的行为。将服务引用添加到托管在Windows服务中的WCF服务时出现问题

此WCF服务旨在成为现有流程的一部分。因此,在IIS或ServiceHost中运行WCF服务不是一种选择。

我的问题是,虽然ServiceHost不会在Open()上抛出错误,但我无法获得“WCF Test Client”(或任何其他)来查找服务。

这是我的第一个WCF服务,并且难以找到适合我所要做的示例或模式。所以我没有幻想,如果我做了很多错误的事情,不会感到惊讶。另外,不是我有'portSharingBinding = false'。我确实已经这样做了,但它抛出了一个指向另一个我不希望运行的服务的错误。 是否需要端口共享?

配置信息:

<system.serviceModel> 
    <bindings> 
    <netTcpBinding> 
     <binding name="PortBinding" portSharingEnabled="false" /> 
    </netTcpBinding> 
    </bindings> 
    <services> 
    <service name="NameChanged.ServiceManager.CommandService"> 
    <endpoint address="net.tcp://localhost" 
       binding="netTcpBinding" 
       bindingConfiguration="PortBinding" 
       name="ServiceManagerCommandChannel" 
       contract="NameChanged.ServiceManager.ICommandService" /> 
    </service> 
    </services> 
</system.serviceModel> 

我也使用以下代码尝试了没有配置路线:

ServiceHost host = new ServiceHost(typeof(CommandService))) 
    host.AddServiceEndpoint(typeof(ICommandService), 
          new NetTcpBinding(), "net.tcp://localhost:8000"); 
    host.Open(); 

另外,在打开没有错误()。但是,连接到服务没有成功。

感谢您的时间,
吉姆

回答

4

我只能给WCF测试客户端说话,但它正在寻找为您服务元数据,因此它可以为它生成一个代理。从上面的配置看,您似乎没有公开元数据交换端点。看看这个链接获取更多信息:

http://weblogs.asp.net/fabio/archive/2009/02/28/net-tcp-mex-endpoints-and-portsharing-in-wcf.aspx

您可以在不使用暴露metatdata生成一个代理访问服务,但是需要你手动创建渠道可以这样做:

http://msdn.microsoft.com/en-us/library/ms734681.aspx

相关问题