Thursday, July 10, 2008

Relearning WCF



I recently had some downtime and wanted to build on my knowledge of WCF. I had previous experience with WCF on using proxy generation but knew that the ChannelFactory existed and I wanted to gain experience using that, so I decided to create a sample WCF Service hosted in IIS on Vista.

So what to do first.....



I knew I wanted to see how to use the ChannelFactory so I went out looking for samples online and found Windows Communication Foundation (WCF) and Windows CardSpace Samples at http://www.microsoft.com/downloadS/details.aspx?familyid=0043041F-95D6-4EB7-966A-C21A737E193A&displaylang=en. I installed this and opened the ChannelFactory solution.


(I had already installed the windows component for IIS (in vista, click start Help and Support and search on Turn Windows features on or off). I selected everything under the IIS Web Mangement Tools section and the IIS World Wide Web Services. I also aready ran the ServiceModelReg.exe -i for the 404.3 error (Read http://msdn.microsoft.com/en-us/library/ms732012.aspx for more explanation).







The next thing I had to do was to make sure that I had an application in IIS set up for the services. During the build, the sample code made a directory under IIS and copied the dlls to it. I knew I either needed to make that an application myself, run the setupvroot found in the WCF_WF_CardSpace_Samples\WCF\Setup\CS, or create an application pointing to the bin directory where my services bin lived. I chose to make an application pointing to the C:\inetpub\wwwroot\ServiceModelSamples folder.

Next, I tried to run the project and it worked but as I'm looked through the code, I wondered how to get the endpoint address to be configurable. I wanted something like
ChannelFactory factory = new ChannelFactory("wsHttpBinding_CalculatorService");

where wsHttpBinding_CalculatorService was defined in my client's app.config.
I had to make the app config look something like



I ran again and it worked. Great! The next thing I wanted to do is try to create my own. I wanted to try extracting out my data contracts and service interfaces so they could be shared between client and server. One of the things I ran into was that the output directory for my services project was pointed to \bin\debug. I had to change that to \bin. I also had issues because I had a virtual directory in iis for the service folder instead of making it an application. I kept getting an error saying

"The service[ServiceName] cannot be activated due to an exception during compilation. The exception message is: The type [ServiceName], provided as the Service attribute value in the ServiceHost directive could not be found. "

Once I made it an application instead of a virtual directory, my sample app worked. Yeah!!!!



Tuesday, April 22, 2008

It's always nice to learn something new

A co-worker recently introduced me to sp_MSforeachtable system stored procedure in SQL Server. I was suprised to find that it has been available for years and I am just now figuring that out. I usually use a cursor to iterate through tables using system objects but I think that this would be much easier to use. As an undocumented stored procedure, I knew that this was a "use at your own risk" but I thought I'd do a little research anyway on the proc to see what kind of things people are doing with this proc and found this forum

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2920286&SiteID=1

stating that sp_MSForEachDb and sp_ForEachTable are both on the deprecation list. Too bad. I wonder what they will replace these procedures with.

Monday, April 21, 2008

Starting out

I want to start my blogging by posting things that have helped me in recent projects. I will continue this over the next few posts. Some will be code and some will be helpful hints when working with day to day software. And to that end.....

In recent projects, we used Sharepoint for a portal and Team Foundation Server. I found that whenever I wanted to access a word 2007 document from either place, it would prompt me for a login even though I had set up my local network in my trusted sites. A co-worker showed me how to resolve this so I would like to pass it on


Open Word 2007
1. Click the last icon in the file menu (pulldown)
2. Select more commands
3. Select Trust center from the left side menu
4. Click Trust center settings button on the lower right
5. On the trusted locations tab check 'Allow trusted locations on my network'
6. Click the add new location button
7. Click Browse
8. Click Desktop
9. Click Network
10. Click on your server that houses TFS
11. Click OK
12. Click OK
13. Close trust center settings.
14. Open a TFS document without entering your password.

I hope this helps someone out there.