コンソール アプリから開始する Windows サービス内で WCF サービスをホストしようとしています。コンソール アプリと同様に、各サービスは独自のプロジェクトです。app.config を WCF サービス ライブラリからコンソール アプリの app.config にコピーしましたが、「サービスにはアプリケーション エンドポイントがありません...」というメッセージが表示され続けます。エラーは私のタイプ参照が完全に修飾されていないことを意味することをいくつかの場所で読みましたが、それを2重(3重、4重...)チェックしました。そして、私は app.config を持っていると確信しています。デバッグ ディレクトリには、コンソール アプリ、コンソール アプリ vshost、Win サービスの 3 つの exe があります。Win サービスには app.config がなかったので、探している場合に備えて app.config をコピーしようとしましたが、うまくいきませんでした。また、構成の名前が正しいことも確認しました (<program>.exe.config)。
これが私が使用しているものです。私のコンソール アプリは と のインスタンスを作成し、JobSchdeuler
を呼び出しますJobSchedulerConsoleStart
。
ホスト コード:
public partial class JobScheduler : ServiceBase
{
ServiceHost jobServiceHost = null;
public JobScheduler()
{
ServiceName = "JobSchedulerService";
InitializeComponent();
}
#region Service Init/Uninit
/// <summary>
/// OnStart
/// </summary>
/// <param name="args"></param>
protected override void OnStart(string[] args)
{
if (jobServiceHost != null)
{
jobServiceHost.Close();
}
jobServiceHost = new ServiceHost(typeof(JobSchedulerWCF.JobService));
jobServiceHost.Open();
}
/// <summary>
/// OnStop
/// </summary>
protected override void OnStop()
{
if (jobServiceHost != null)
{
jobServiceHost.Close();
jobServiceHost = null;
}
}
#endregion
#region Debugging
public void JobSchedulerConsoleStart()
{
this.OnStart(null);
Console.WriteLine("Service Started.");
ProcessInput();
Console.WriteLine("Service Stopped.");
this.OnStop();
}
private void ProcessInput()
{
Console.WriteLine("Press any key to quit...");
Console.ReadKey();
}
#endregion
}
app.config
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<services>
<service behaviorConfiguration="JobSchedulerWCF.Service1Behavior" name="JobSchedulerWCF.JobService, JobSchedulerWCF">
<endpoint address="" binding="wsHttpBinding" contract="JobSchedulerWCF.IJobServiceController, JobSchedulerWCF">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:12345/jobService"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="JobSchedulerWCF.Service1Behavior">
<!-- To avoid disclosing metadata information,
set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="True"/>
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>