次の方法で共有


WebMatrix (IISExpress) Beta - Hosting WCF Services

First off, see ScottGu's blog post on IISExpress: https://weblogs.asp.net/scottgu/archive/2010/06/28/introducing-iis-express.aspx

Next, if you need the download link for the beta, it's here: https://www.microsoft.com/web/webmatrix/

Okay, and now on to the purpose of this blog post -

How to host a WCF service with WebMatrix beta

If you get the following error when you try to activate a WCF service hosted in WebMatrix:

Could not load file or assembly 'Microsoft.Web.Administration, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

Then you need to implement some work around for assembly redirection.  See, System.ServiceModel.Activation uses functionality in Microsoft.Web.Activation.dll and Microsoft.Web.dll in order to access properties of the web server (usually IIS.)  For WebMatrix, there's a special different Microsoft.Web.Administration.dll which targets the ApplicationHost.config file for WebMatrix instead of the ApplicationHost.config for IIS.  In short, the simplest way I've found to work around this issue is to GAC these two assemblies for the beta release.  Open a Visual Studio Command Prompt, as admin, and enter the following two commands:

· gacutil /i “C:\Program Files\Microsoft WebMatrix\Microsoft.Web.Administration.dll”

· gacutil /i “C:\Program Files\Microsoft WebMatrix\Microsoft.Web.dll”

Restart the website (or maybe restart WebMatrix) and try activating the WCF service again.  It should work this time.

A brief word about actually hosting WCF in WebMatrix beta (aside from the work-around)

If you are familiar with hosting WCF services in IIS, hosting in WebMatrix isn't that much different, besides the above work-around.  If you have the physical directory all set up to be used as your virtual directory, you can simply open WebMatrix and click "Site From Folder" and point to this physical directory.  That's it.  In the next view WebMatrix presents, you can browse to the .svc site using IE.