Learning WCF
21-Apr-1414 Leave a comment
With help from book “Learning WCF” by Michele Leroux Bustamante
Notes from working through samples:
Note 1:
Surprisingly it is possible/advisable to host the service from a different project or projects. This gives the possibility of one service to have different types of host running
Error 1: System.ServiceModel.AddressAccessDeniedException: HTTP could not register URL http://.. Your process does not have access rights to this namespace
Solution 1:
Run Visual Studio as an administrator
Error 2: App.Config does not have context menu option “Edit WCF configuration”
Solution 2:
Use Tools > WCF Service Configuration Editor then close it
Then right-click on App.Config and the “Edit WCF configuration” will be there
Error 3: ASP.Net HTTP Error 403.14 – Forbidden – The Web server is configured to not list the contents of this directory
Solution 3:
- IIS
- Select the web site
- Double-click Directory Browsing
- Enable
(Nice to have an easy problem)
Error 4: IIS – Web site – Configuration Editor – system.web/compilation – Bug Unrecognized element folderlevelbuildproviders
Solution 4
With thanks to:
http://forums.iis.net/t/1180915.aspx which led to
http://www.hanselman.com/blog/ASPNET4BreakingChangesAndStuffToBeAwareOf.aspx
If you install ASP.Net 4 and then install IIS then you need to make sure IIS is configured to know about ASP.Net 4 otherwise IIS will have no idea how to run ASP.Net 4 applications.
There’s a simple workaround:
- If you are already in this state, drop to the command line and navigate to the FX install directory. Then run “aspnet_regiis –iru“.
- Note if you are on a 64-bit machine, run this command from the 64-bit FX install directory – not the 32-bit installation directory.
or for future reference, try to enable IIS and the ASP.NET extensibility option *first* when your are building machines or VMs. That way when VS 2010 or .NET are subsequently installed, the installation will automatically detect the presence of IIS and will auto-register with it.
How to host a service in a solution and have the client add service reference
Run without debugging – to do this use Ctrl + F5 or use the Debug menu, but the option may not be there, if you start with a VB IDE. If it is not there then you may add it using customise.
If you run with debugging as usual you will not be able to edit the client.
Hosting the service in IIS
Error no website with code 500
Not surprised that I had issues with hosting here. I had a WSS Windows SharePoint Services and SharePoint Central Administration using my IIS. Took a while to sort, what follows is not comprehensive, but a guide to what I did. I took the view that I have not used SharePoint Central Administration and so was prepared to sacrifice it. Some steps included:
IIS > Sites > Default Web Site > Right-Click > Edit Bindings.
Remove all bindings except http
Then under Default Web Site I had a folder wss -> Virtual Directories -> 80 -> my sample application landed here. Not sure why.
I removed all SharePoint (80) web sites, hope that is ok. And archived the wss folder in its entirety.
Everything started working again.
WCF Test Client executable
C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\WcfTestClient.exe
Useful quick test.