2015-08-26 118 views
-3

我必须在.NET 2.0环境中的C#控制台应用程序中创建运行的Web服务。 我无法使用WCF或将目标系统升级到最新的.NET版本。创建.NET 2.0独立WebService

我搜索了很多,但没有找到合适的东西。

有人有建议吗?

+2

问不管是谁上没有升级,坚持,如果他们真的很高兴为解决对已停工[主流支持]的基础之上(https://support.microsoft.com/en建-us/lifecycle/search?sort = pn&alpha = .net%20framework)已经有近4年的时间了,只剩下一年多一点的延长支持。 –

+0

你甚至可以得到一个至少没有安装.NET 3.5.1的操作系统吗?当然,这意味着操作系统无法得到更广泛的支持。 – Aron

+0

不幸的是,Web服务也将安装在Windows 2000和.NET 2.0的旧版本环境中。我们不允许更新.net或升级o/s – Slevin

回答

0

这是一个如何在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); 
     } 
    } 
+0

尽量避免发布仅链接的答案,因为它们被认为质量差(以及链接可能会在未来中断) – Jonesopolis

+0

如果您为控制台应用程序,这将是一个实际的答案的问题。不要忘记说明OP需要WSE3.0下载才能执行此操作。 – rene