Blogger :
steve maines blog
All posts :
All posts by steve maines blog
Category :
WSCF/WCF
Blogged date : 2006 Feb 07
I've boxed up my AJAX-enabled "Web 2.0 Business Idea Generator" demo from VSLive!
San Francisco. If you're feeling anxious, you can skip all this and just download
the code from here.
I've tried to comment the interesting bits fairly liberally.
This sample is built on the Nov/Jan releases of WCF -- either one should work.
There are two solutions in the .zip. PoxService.sln has just the service and the client.
PoxService_With_UnitTests.sln has the client, the service, and a VSTS unit test project
as well (take a look at that if you want to see one way WCF services can be targeted
by unit tests). To run the demo, just load it up in Visual Studio and hit F5. Things
should be self-explanatory from there.
The demo is based on a pretty simple concept: you've got a client (an .aspx page)
that uses XmlHTTPRequest to do an HTTP GET on some URI. The client takes the results
of that GET and updates the page with the new data. On the service side, the thing
that's responding to that HTTP GET is a WCF endpoint.
Download the code (190k),
run the demo, and take a look at the implementation. Make sure you get the full tour:
The AjaxClient Project
-
The AJAX client code lives in a script block on Default.aspx. This is pretty bog-standard
AJAX code...nothing Indigo-specific here.
-
Ideas.svc is a one-liner that hosts the Indigo service. The implementation of this
service lives in the PoxServices project.
-
Web.config has several handy examples of using some of the more advanced features
of the WCF configuration system. Again, all the interesting bits should be commented.
PoxServices.dll
-
Service contract and implementation live in PoxBusinessIdeaGenerator.cs.
-
The service uses a universal contract (message-in, message-out, any action) to respond
to every message sent to the endpoint.
-
The implementation of ProcessMessage() show how to fish out HTTP headers from the
messsage and construct raw HTTP responses.
-
The 'business logic' of GetIdea() stores some results in ASP.NET session state, showing
how WCF can play nicely with ASP.NET features.
-
There's a custom encoder implementation (thanks to douglasp for that) that also includes
full configuration support. A detailed discussion of how that works will be left for
another time, though.
Have fun.