Deploying a WCF service both in IIS and as Windows service

Is it possible to have one WCF service project that can be deployed both as a Windows service and also as a web service hosted in IIS?  I would like to be able to do this without having to create two separate projects in Visual Studio, but I cannot figure out how to do it.

I have created a project of type "WCF Service Application" and I can get this working as a web service in IIS very easily.  Should I have used a different project type to be able to do the Windows service as well?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You could do it by creating two endpoints.

Also just in case you want to host in windows service then you would have to write the host also.

I am not sure of your scenario why you are preferring windows service. If it is just to support a protocol other than http then you could host it in WAS(Windows Process Activation Service) it supports HTTP,TCP, NAMED PIPES, MSMQ etc and provides all the features that IIS provides.

Note that WAS is available from Windows Vista and up and I guess Windows 2003 server and up
BRNIITAuthor Commented:
Thank you, SriVaddadi - that is a good suggestion.  I will look into that, but let's say I do want to use Windows services.  Isn't an .exe required, and therefore a console application project?  Would I have to copy code from one project to another, and maintain them both, or is there a way to do it with the same project and code?
Lets say you would go with hosting with managed windows service then your solution would have two projects.

1. WCF service itself
2. Windows service which would host your WCF service

WCF service would have two end points. One for http which is for hosting in IIS and another for hosting in windows service.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BRNIITAuthor Commented:
Thank you for the information, SriVaddadi.  Very helpful.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.