私のソリューションには3つのプロジェクトがあります。
- Test Client => tcp ip 経由で参照とアクセスを追加するため
- WcfServiceLibruary1 => 私の方法を実行するため
- WindowsService1 => Windows サービスとしてインストールして実行する場合 (アカウント:ネットワーク サービス、開始タイプ:自動)
msdnサンプルですべて同じコードを使用しました
http://msdn.microsoft.com/en-us/library/ff649818.aspx
2 つのメソッドを持つ wcf サービスを使用しています。マネージド 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>
私の WindowsService :
protected override void OnStart(string[] args)
{
if (myServiceHost != null)
{
myServiceHost.Close();
}
myServiceHost = new ServiceHost(typeof(Service1));
myServiceHost.Open();
}
VisualStudio サービス ホストで起動すると、すべてが正常に機能します。