我正在爲現有的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();
另外,在打開沒有錯誤()。但是,連接到服務沒有成功。
感謝您的時間,
吉姆