[英]How to Host a WCF Service in a Managed Windows Service?
我的解決方案中有3個項目。
我在msdn示例中使用了所有相同的代碼
http://msdn.microsoft.com/en-us/library/ff649818.aspx
我使用的wcf服務有2個methots。我想在托管Windows服務中使用此wcf服務。我在解決方案中添加了Windows服務並設置了引用內容。
我在wcf-app.config上使用此地址引用:
net.tcp://localhost:2023/Service1
現在的問題是:
我成功使用添加了對我的測試客戶端項目的引用
net.tcp://localhost:2023/Service1
:
但是此引用地址不能在Windows服務中安裝!!! 當我將其安裝為Windows服務時,無法訪問該地址,並且出現此錯誤: No connection could be made because the target machine actively refused it
WcfServiceLibruary app.config:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true"/>
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<services>
<service name="WcfServiceLibrary1.Service1">
<endpoint address="" binding="netTcpBinding" bindingConfiguration="" contract="WcfServiceLibrary1.IService1">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:2023/Service1"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="false"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
我的Windows服務:
protected override void OnStart(string[] args)
{
if (myServiceHost != null)
{
myServiceHost.Close();
}
myServiceHost = new ServiceHost(typeof(Service1));
myServiceHost.Open();
}
當我在visualstudio服務主機上啟動時,一切工作正常:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.