콘솔 앱을 통해 시작하는 Windows 서비스에서 WCF 서비스를 호스팅하려고합니다. 각 서비스는 콘솔 앱과 마찬가지로 자체 프로젝트입니다. WCF 서비스 라이브러리의 app.config를 콘솔 응용 프로그램의 app.config에 복사했지만 "서비스에는 응용 프로그램 끝점이 없습니다 ..."라는 메시지가 계속 나타납니다. 나는 몇몇 장소에서 오류가 내 타입 참조가 완전하지 않다는 것을 의미하지만, 나는 double (트리플, 쿼드 러플 ...)을 체크했다. 그리고 저는 app.config를 가지고 있다고 확신합니다. 디버그 디렉토리에는 Console App, Console App vshost, Win Service 등 3 개의 exes가 있습니다. 윈 서비스는 app.config를 가지고 있지 않았기 때문에, app.config 파일을 찾고자 할 때를 대비해 복사를 시도했지만 운이 없었다. 또한 configs의 이름이 올바르게 지정되었는지 확인했습니다 (< 프로그램 > .exe.config).WCF 서비스 자체 호스팅 문제
다음은 내가 사용하는 것입니다. 내 콘솔 앱은 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>
호스트 코드도 제공해 주시겠습니까? – Philippe
코드가 제공되었습니다. –