Chong
Chong

Reputation: 604

To expose WCF service as asmx(web service) and hosted in window service

I am developing the wcf application in VS2008. I want to host that WCF service as window service. But I also want to expose that service as .asmx(web service).

Is it possible to do? Is there any way to expose wcf service as .asmx(web service) but need to host in window service.

Upvotes: 0

Views: 2125

Answers (1)

Alejandro Martin
Alejandro Martin

Reputation: 5877

When hosted as windows service, you can set the base address of your service to any URL you want, for example:

(Assuming that you already have a class called "yourServiceClass" implementing the service contract)

public class ExampleWindowsService : ServiceBase
{
    public ServiceHost host = null;

    public static void Main()
    {
        ServiceBase.Run(new ExampleWindowsService());
    }

    protected override void OnStart(string[] args)
    {
        if (host != null)
        {
            host.Close();
        }
        Uri baseAddress = new Uri("http://localhost:80/yourservice.asmx");
        host = new ServiceHost(typeof(yourServiceClass), baseAddress);
        host.Open();
        Console.WriteLine("Service hosted ...");
    }
}

Then you can add the endpoints and behaviors you need, either programatically or by configuration file. Look here to find more info about how implement a WCF service as windows service.

Upvotes: 4

Related Questions