.net WCF服务自托管故障
我正在尝试在Windows服务中托管WCF服务,我正在通过控制台应用程序启动该服务。与控制台应用程序一样,每个服务都是自己的项目。我已将app.config从WCF服务库复制到console应用程序的app.config中,但我一直认为服务没有应用程序终结点。。。。我在一些地方读到过,这个错误意味着我的类型引用不是完全合格的,但我有两个、三个、四个。。。检查过了。我很确定我有一个app.config。我的调试目录中有3个EXE:控制台应用程序、控制台应用程序vshost、Win服务。Win服务没有app.config,所以我尝试复制它的app.config,以防它正在寻找它,但没有成功。我还检查了以确保配置的名称正确。exe.config 这是我用的。我的控制台应用程序创建JobSchdeuler实例并调用JobSchedulerConsoleStart 主机代码:.net WCF服务自托管故障,.net,windows-services,wcf,self-hosting,.net,Windows Services,Wcf,Self Hosting,我正在尝试在Windows服务中托管WCF服务,我正在通过控制台应用程序启动该服务。与控制台应用程序一样,每个服务都是自己的项目。我已将app.config从WCF服务库复制到console应用程序的app.config中,但我一直认为服务没有应用程序终结点。。。。我在一些地方读到过,这个错误意味着我的类型引用不是完全合格的,但我有两个、三个、四个。。。检查过了。我很确定我有一个app.config。我的调试目录中有3个EXE:控制台应用程序、控制台应用程序vshost、Win服务。Win服务没
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>
您的配置文件是否命名 Console.App.exe.config Win.Service.exe.config ? 编辑:如果我没记错的话,WCF的Beta版本和服务名称有问题 尝试改变
<service behaviorConfiguration="JobSchedulerWCF.Service1Behavior" name="JobSchedulerWCF.JobService, JobSchedulerWCF">
到
删除配置文件中的程序集名称
请让我知道这是否解决了问题。我没有把它绑起来。我从来没有弄清这件事的真相。配置/项目中有点不对劲。我重新构建了解决方案,问题就消失了。您能否向我们提供主机代码?
<service behaviorConfiguration="JobSchedulerWCF.Service1Behavior" name="JobSchedulerWCF.JobService">