Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
353 views
in Technique[技术] by (71.8m points)

.net - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...