Friday, January 08, 2010

First WCF program on Windows Vista

I got a WCF Unleashed book and started going through it. As the book reading progressed, I started trying the examples explained in the book on my Vista laptop. Surprisingly I had to workaround many things to get things set right. None of the steps worked as is. Hence the blog post.
My laptop is running Vista SP2 Home Premium. This edition of Vista comes up with IIS 6.1, I think (It needs to be enabled using Windows Add Remove components).
The first example I was trying was to create a simple WCF service(1 operation defined in contract), host it in a simple Console host. I created a client using standard svcutil.exe tool. The client was supposed to access the WCF service using basicHttpBinding. Projects were ready everything looked simple till this point.
I ran the WCF service, and bummer, it threw an exception which said something like you don’t have access to the HTTP address. It was referring to the HTTP address which I had specified in the app.config for the WCF service host. Looked around and found that I need to use, netsh command to grant permission to listen on the ports. Many blog entries said this is a new security feature with Vista. With this I was able to run the service( using the console host ). With service running I was also able to connect using the Client and everything looked fine.
After this, I tried to deploy the service in IIS. Followed the instructions from the book, created a virtual directory pointed to the service ( this time just the contract) solution's output directory. Everything looked fine. Then I tried to access the URL from the browser and bummer IIS 500 error. It said something like, bad configuration data. I re-verified the web.config it looked all right. Again, back to Google searching for this , I came across some blogs which said we need to first register WCF before one can use the WCF service. This looked strange to me in first place then it kind of made sense. To install WCF I used ServiceModelReg.exe -I. This looked something similar to the ASP.Net registration utility for IIS.
Once WCF is installed I had to install ASP.Net as well. It would have been great if it would have been pre installed in IIS Emoticon1.
Also I needed to grant Read permission to IIS_IUSRS and IUSR built in users on the physical directory.
I was kind of relieved at this point, and was all geared up to test it. Here I try and get another error , crap.
This time the error said,
The type , provided as the Service attribute value in the ServiceHost directive could not be found.

I had hard time getting around this. I finally went to Fusion Log Viewer to check which assembly bindings are failing. This tool showed, the loader is looking for the assembly where the type is defined in the \bin directory. The assembly was in the same location where the Service.svc file was located. Also the virtual directory I created was pointing to the \bin directory for the service Visual Studio project. So I ended up creating a new directory bin inside bin directory and copied the assembly there.
After all this it worked finally hoo hoo Emoticon1[1]
Thanks
Prasad

No comments: