代码如下,实现把MathService注册为windows自己的Service,但是总是在
“ServicesToRun = ServiceBase[]{new MathService()};”编译不过,请
高人指点!!!!
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
//using System.ServiceProcess.ServiceBase;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;namespace MathService
{
public class MathService : System.ServiceProcess.ServiceBase
{
/// <summary> 
/// Required designer variable.
/// </summary>
/// 
private System.ComponentModel.Container components = null;

static void Main()
{
ServiceBase[] ServicesToRun;
ServicesToRun = ServiceBase[]{new MathService()};
ServiceBase.Run(ServicesToRun);
} public MathService()
{
// This call is required by the Windows.Forms Component Designer.
InitializeComponent(); // TODO: Add any initialization after the InitComponent call
} #region Component Designer generated code
/// <summary> 
/// Required method for Designer support - do not modify 
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
this.ServiceName = "MathService";
}
#endregion
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing ) 
{
if( disposing )
{
if (components != null) 
{
components.Dispose();
}
}
base.Dispose( disposing );
} /// <summary>
/// Set things in motion so your service can do its work.
/// </summary>
protected override void OnStart(string[] args)
{
// TODO: Add code here to start your service.
//Configure the channel
HttpChannel channel = new HttpChannel(13101);
ChannelServices.RegisterChannel(channel); //Register SimpleMath as well-known Singleton
RemotingConfiguration.RegisterWellKnownServiceType(typeof(MathLibrary.SimpleMath),"SimpleMath.soap",WellKnownObjectMode.Singleton); }
 
/// <summary>
/// Stop this service.
/// </summary>
protected override void OnStop()
{
// TODO: Add code here to perform any tear-down necessary to stop your service.
}


}
}