The following is the procedure to host a web service in windows service.
- Open Visual Studio 2005.
- Create an ASP.NET Web service.
a. File menu, choose New Web Site
b. In the New Web Site dialogue box, select the ASP.NET Web Service.
c. Enter the address of web server and click Ok.
3. Add code to implement the Web Service.
4. Create a Windows service.
a. File menu, choose New Project
b. In the New Project dialogue box, select windows service.
c. Specify the name and click Ok.
5. Add references to the Microsoft.Web.Services3, System.Web.Services, and System.Web assemblies.
6. Add source file and configuration file to the Windows service project.
a. Right click the windows service project, point to Add choose Existing Item.
b. Navigate to the configuration file in the web service folder select
Web.config, and click Add.
c. Right click the windows service project, point to Add choose Existing Item.
d. Navigate to App_code folder web service project select the source file
Service1.cs, and click Add.
e. Rename the Web.config file to app.config.
7. Open the source file in windows service project
write the following code in OnStart Method
protected override void OnStart(string[] args) { Uri address = new Uri("soap.tcp://localhost/TestService"); SoapReceivers.Add(new EndpointReference(address), typeof(Service )); }
8. Write the following code in OnStop Method.
protected override void OnStop(){ SoapReceivers.Clear(); }
9.Write the following code in Main Method
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); }
10. Install the Windows Service.
Hosting a Webservice in windows service…
You’ve been kicked (a good thing) – Trackback from DotNetKicks.com…
nice article to implement web services.