I recently downloaded the WCF and WF samples to begin looking at the Federation sample. The topic of federated security in WCF is an interesting one and I will write about my experience with it in a future post; however, I wanted to address a more basic situation that I ran into while working with the sample project.
I opened the solution in Visual Studio 2010 and compiled it. After successfully compiling, I attempted to run the client project, which is configured as the startup project. The app started, but the browse books capability failed because I had not deployed the web service that the application required in order to get data. * In the interest of disclosure, I did not follow the recommendation of using the setup.bat to create and deploy the web site and related applications to host the STS and app services because I wanted control over where/how they were created.
The information in this post is admittedly pretty basic, but in my experience these simple steps are sometimes missed making it impossible to test your service. Therefore, in this post I will list the simple steps needed to publish/deploy a WCF service to IIS.
If you need more information on WCF, just check out the Beginner’s Guide to Windows Communication Foundation. There you can find a lot of useful information on writing WCF services and exploring the various hosting options available to you.
Create a New Web Site
After writing your service or compiling the sample you’re working with, you need a web site to host it. Assuming you have a working service implementation…
1.) Click Start\Run and type ‘inetmgr’ (assuming you already have IIS installed)
2) Right click sites, and add a new site. In my case, I created the BookStore site. I created the physical path C:\inetpub\wwwroot\Bookstore
3) I then created a subdirectory for web services. C:\inetpub\wwwroot\Bookstore\Services and a bin folder to put the binaries in that you just compiled. You should end up with a directory structure like this: C:\inetpub\wwwroot\<yoursite>\Services\bin.
Copy the Content to the New Site
4) Copy the DLLs from your services bin\debug or bin\release folder to the …\<yoursite>\Services\bin folder.
5) Copy the web service’s .svc and web.config files into the …\<yoursite>\Services folder. If your service has any additional files that it needs to function, copy them to that folder as well. The Book Store example needed a .txt file for its data.
Create a New Application to Host the Service
6) In the IIS Manager, create a new application for your services folder. Do this by right-clicking the Services folder and select, “Convert to Application”. Select your newly created Services folder for the physical folder and click OK. Make note of the application pool that you selected.
7) Change the application pool’s advanced settings to select the .NET Framework 4.0 (assuming you’re using 4.0 – if not be sure the right version of .NET for you is selected).
Set the ACL on Your Physical File Folders
8) Grant access to the application pool identity to your file folder. The identity that you select will be IIS AppPool\<AppPoolName>.In my case it was IIS AppPool\BookStore. Be sure to grant it Read & execute, List folder contents, and Read.
If you happen to miss this step, IIS cannot load your service assemblies.
9) That’s it! To test your service, you should be able to select the .svc file in the IIS Manager and click Browse and get a screen that describes your service.
Good luck!
/imapcgeek
No comments:
Post a Comment