What is the purpose of WCF Service Library?

What is the purpose of WCF Service Library? I understand if you build an IIS hosted service you create a web project, if self-hosted - create an .exe.

What is a real life scenario to use WCF as DLL?


"WCF Service Application” itself is a direct web service application relying on WCF technology (which is similar to the ASP.NET web service development). "WCF Service Library" on the other hand is a compiled component which can be deployed as a web service or a Windows service or even as a part of a customized hosting application.

- Developing a WCF Service Library and Hosting it as a WCF Web Service

While it's true that creating a WCF service as a class library gives you more flexibility, that flexibility comes at a cost, and it's a mistake to assume that the more flexible solution is always the preferred solution, or that the less flexible solution is childish or only suitable for "simple instructional purposes".

The vast majority of WCF services are hosted as web services and will never be deployed any other way.

Here are three advantages of using a WCF service application as opposed to a WCF class library:

  1. If you create your web service as a class library the configuration files will be app.config files rather than web.config files. App.config files don't natively support multiple configuration files and config transforms the way web.config files do. If you want config transforms on your app.config files you have to use a third party solution such as Slow Cheetah.

  2. When it's time to publish your site, if you use a WCF service application you can take full advantage of Web Deploy (http://www.iis.net/downloads/microsoft/web-deploy) which is a powerful and flexible way to publish your solution to IIS.

  3. If you decide to automate your build and deploy for continuous integration with TFS there will come a time when you'll want to automate the publishing of your service. If you use a WCF service you can configure TFS to run Web Deploy, which will merge your web.config files according to the target build configuration, perform incremental publish, enable publishing without administrator rights on the server and other benefits. If you use a WCF class library then you will have to write a custom workflow solution to merge the app.config files, use xCopy for deployment, and generally have a tougher time automating the deployment.

In summary the more flexible solution, as is often the case, comes at the cost of losing specific tool support. If, like most WCF service solutions, your application will always be hosted in IIS, you might consider taking advantage of this support by using a WCF service application as opposed to a WCF class library.

I would always create a WCF library as a class library - it's much easier to use. You have total flexibility to then either host your WCF service inside IIS (by supplying a virtual directory and a .svc file inside it), or you could write your own self-hosting EXE and reference the WCF service in the class library from it.

Putting a WCF service directly into a web project seems like a really bad idea and might only be useful for very simple instructional purposes - just to show how to get started. I would never do this for a "live" system.


Need Your Help

JCrop: Prevent de-selection?

jquery image-processing jcrop

I'm currently setting up an image-upload cropping sequence.

MySQL disable all triggers

mysql triggers information-schema

For test correctness of query I need disable all triggers in db.