创建.net 2.0独立web服务
本文关键字:web 服务 独立 net 创建 | 更新日期: 2023-09-27 18:10:06
我必须在。net 2.0环境中创建一个运行在c#控制台应用程序中的Web服务。我无法使用WCF或将目标系统升级到最近的。net版本。
我已经谷歌了很多,但没有找到任何合适的。
有人有建议吗?
这是一个如何在windows服务中托管web服务的老例子。
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{
public Service () {
}
[WebMethod]
public string HelloWorld() {
return "Hello World";
}
}
public partial class WindowsServiceToHostASMXWebService : ServiceBase
{
public WindowsServiceToHostASMXWebService()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
Uri address = new Uri("soap.tcp://localhost/TestService");
SoapReceivers.Add(new EndpointReference(address), typeof(Service ));
}
protected override void OnStop()
{
SoapReceivers.Clear();
}
static void Main()
{
System.ServiceProcess.ServiceBase[] ServicesToRun;
// Change the following line to match.
ServicesToRun = new System.ServiceProcess.ServiceBase[] { new WindowsServiceToHostASMXWebService() };
System.ServiceProcess.ServiceBase.Run(ServicesToRun);
}
}