Today I decided to take a look at the WCF/WF Samples for .NET 4. There are quite a lot of them but to be honest with you I have not found them to be very helpful. In the spirit of trying to make things better I’m going to review the sample with you.
I decided to start with the WCF samples and the first one I’m starting with is the ComplexTypeAjaxService.
I went through the One-Time Set-Up Procedure for the Windows Communication Foundation Samples which is lengthy and enough to scare most people away but I made it through.
Now I open up ComplexTypeAjaxService.sln. So far so good, but when I try to look at ComplexTypeClientPage.aspx it crashes VS2010 RC (I tried several times with the same result) so I looked it over in notepad.
So I decide to build the sample. It has a Post-build command line that tries to create directories and copy files to the VRoot which requires admin privileges so it fails because I haven’t run VS2010 with admin privileges.
I start VS2010 again with Admin Privileges and build the sample. Then I try to browse the file and get another error about the web.config. I’m wondering why it doesn’t just run in the ASP.NET Development Server so I switch back to VS2010 and try to view the .aspx page in the browser (which should launch the development server) but instead I get a browser window that just hangs.
I decide to look at the project properties to see what is going on and I find that the project is not a web app. It is a class library (which explains why it behaves so strangely).
I think I’m going to start a new project that doesn’t suffer from all these pains and give it a go.
So I do the following
- Create an Empty ASP.NET Application
- Add an AJAX-enabled WCF Service named Calculator
- Add a class named MathResult and copy over the class from the sample
- Remove DataContract / DataMember since they are no longer required but are optional
- Paste in the HTML from the original project (fixed up with table formatting so it looks better)
- Added some simple styling and page title
- Supplied default values
Now I’ve got a nice sample that works quite well and it took just a couple of minutes. Check it out