当我尝试安装我的服务时,我收到以下错误:
Exception Occured while initializing the installation:
System.IO.FileNotFoundException: Could Not load file or assembly 'file:///C:\...\bin\Debug\OrionRAService' or one of its dependancies.
The System cannot find the file specified.
我正在使用visualstudio命令行安装,而且我在正确的目录中。我知道该文件存在,因为我可以在我的文件浏览器中看到它。 下面是我的服务代码(至少是服务的部分,遗漏的是计算和内容):
using System;
using System.Runtime.Serialization;
using System.Collections.Generic;
using System.ComponentModel;
using System.ServiceModel;
using System.ServiceProcess;
using System.Configuration;
using System.Configuration.Install;
using System.IO;
using System.Xml;
using System.Xml.Linq;
namespace OrionRAService
{
// Define a service contract.
[ServiceContract(Namespace = "http://OrionRAService")]
public interface ICalculator
{
[OperationContract]
List<Profile> CollectAllProfiles();
[OperationContract]
bool IsItActive(Profile P);
[OperationContract]
void ChangeProfileActivity(Profile p,bool isActive);
[OperationContract]
void ChangeDaysToKeepData(int DayCount);
//[OperationContract]
//void CollectOnActiveProfiles(DateTime startTake, DateTime endTake);
}
[DataContract]
public class Profile
{
//... ... ...
}
public class CalculatorService : ICalculator
{
//implementation of all methods from ICalculator
}
public class CalculatorWindowsService : ServiceBase
{
//... ... ...
public ServiceHost mHost = null;
//... ... ...
public CalculatorWindowsService()
{
// Name the Windows Service
ServiceName = "OrionRAService";
}
public static void Main()
{
ServiceBase.Run(new CalculatorWindowsService());
}
protected override void OnStart(string[] args)
{
if (mHost != null)
{
mHost.Close();
}
mHost = new ServiceHost(typeof(CalculatorService), new Uri("net.pipe://localhost"));
mHost.AddServiceEndpoint(typeof(ICalculator), new NetNamedPipeBinding(), "MyServiceAddress");
mHost.Open();
//... ... ...
}
protected override void OnStop()
{
if (mHost != null)
{
mHost.Close();
mHost = null;
}
}
}
// Provide the ProjectInstaller class which allows
// the service to be installed by the Installutil.exe tool
[RunInstaller(true)]
public class ProjectInstaller : Installer
{
private ServiceProcessInstaller process;
private ServiceInstaller service;
public ProjectInstaller()
{
process = new ServiceProcessInstaller();
process.Account = ServiceAccount.LocalSystem;
service = new ServiceInstaller();
service.ServiceName = "OrionRAService";
Installers.Add(process);
Installers.Add(service);
}
}
}
这是App.Config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<!-- This section is optional with the new configuration model
introduced in .NET Framework 4. -->
<service name="Microsoft.ServiceModel.Samples.CalculatorService"
behaviorConfiguration="CalculatorServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000/ServiceModelSamples/service"/>
</baseAddresses>
</host>
<!-- this endpoint is exposed at the base address provided by host: http://localhost:8000/ServiceModelSamples/service -->
<endpoint address=""
binding="wsHttpBinding"
contract="Microsoft.ServiceModel.Samples.ICalculator" />
<!-- the mex endpoint is exposed at http://localhost:8000/ServiceModelSamples/service/mex -->
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="CalculatorServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="False"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>