Newly Posted – WCF REST Starter Kit Preview 2

Happy Thursday everyone,


Earlier this afternoon, the WCF REST team released the second preview release of the WCF REST Starter Kit onto CodePlex. Today’s release adds new client capabilities that we think should really make client-side REST development easier. Chief among the new functionality included in Preview 2 is a new class that provides a staged pipeline model for requesting resources over the web. Using this new HTTP client class allows the developer to plug into the various stages of communication to handle custom authentication, caching, and fault handling outside of the client’s application logic.


For those new to the WCF REST Starter Kit – it’s a collection of preview functionality that makes use of WCF to implement REST architectural patterns. The kit includes new features, Visual Studio templates, samples and guidance that enable users to create REST style services using WCF. The goal of the kit is to provide a toolset that simplifies building RESTful services today, and to get feedback from you on the features provided in the WCF REST Starter Kit – feedback that will shape future REST capabilities in WCF, in .NET 4 and beyond.


The initial release of the WCF REST Starter Kit (in October, 2008) focused on building server-side REST services, with a heavy focus on the Visual Studio project templates that help developers get a jump start developing in a RESTful manner. Since the October release, the team has received some excellent feedback and added a few additional team members, Ron Jacobs (the top evangelist around all things Workflow and WCF) has created a few hands on labs, and Aaron Skonnard has done a few screencasts for the kit.


With the release of these new bits, it’s my pleasure to also announce the following:



  • Updated REST in WCF Dev Center on MSDN: The MSDN Dev Center for REST in WCF has been updated to account for the wider topic of REST in WCF, rather than purely focusing on the REST Starter Kit. In the coming weeks, we will be adding blog feeds to the site (similar to the parent WCF Dev Center).

  • Updated Hands On Labs: Ron has updated his WCF REST hands on labs, which contains labs that cover both REST development using WCF in .NET 3.5 SP1, as well as developing using the WCF REST Starter Kit. The labs provide an excellent guided tour for the newbie in all of us.

  • New WCF REST Sample Application: The product management crew here has been working to develop a sample application that demonstrates how to make use of the WCF REST Starter Kit on the client and server to create a training portal. The application is pretty sweet, and we look forward to sharing more information about this in the coming week.

  • New Screencasts: We’ve also been working with Aaron to get some new screencasts on the new features in the new preview of the WCF REST Starter Kit. The new screencasts should start landing onto the Endpoint show on Channel9 in the coming week.

We’re hoping that you download the latest preview release and give it a try. Feel free to drop into the WCF REST Starter Kit forum over on the ASP.NET site and give us feedback. The team is on the forum daily, and is using the feedback to tweak and improve the features and functionality.

Consuming the Twitter REST API with HttpClient (WCF REST Starter Kit)

Consuming the Twitter REST API with HttpClient (WCF REST Starter Kit)

A piece of code is worth a thousand words, right? 

try
{
    // initialize HttpClient for Twitter REST API
    HttpClient http = new HttpClient("http://twitter.com/statuses/");
    http.TransportSettings.Credentials =
        new NetworkCredential(twitterUsername, twitterPassword);
    HttpResponseMessage resp = null;

    // retrieve Twitter friends timeline
    resp = http.Get("friends_timeline.xml");
    resp.EnsureStatusIsSuccessful();

    // print all friends statuses
    var statuses = resp.Content.ReadAsXElement().Descendants("status");
    foreach (XElement status in statuses)
        Console.WriteLine("{0}: {1}",
            status.Element("user").Element("screen_name").Value,
            status.Element("text").Value);

    // update your Twitter status
    string newStatus = "writing my first HttpClient app";
    HttpUrlEncodedForm form = new HttpUrlEncodedForm();
    form.Add("status", newStatus);
    System.Net.ServicePointManager.Expect100Continue = false;
    resp = http.Post("update.xml", form.CreateHttpContent());
    resp.EnsureStatusIsSuccessful();
}
catch (Exception ex)
{
    Console.WriteLine(ex.Message);
}

Consuming the Twitter REST API with HttpClient

Consuming the Twitter REST API with HttpClient

A piece of code is worth a thousand words, right?  HttpClient is a new feature in the WCF REST Starter Kit Preview 2.

try
{
    // initialize HttpClient for Twitter REST API
    HttpClient http = new HttpClient("http://twitter.com/statuses/");
    http.TransportSettings.Credentials =
        new NetworkCredential(twitterUsername, twitterPassword);
    HttpResponseMessage resp = null;

    // retrieve Twitter friends timeline
    resp = http.Get("friends_timeline.xml");
    resp.EnsureStatusIsSuccessful();

    // print all friends statuses
    var statuses = resp.Content.ReadAsXElement().Descendants("status");
    foreach (XElement status in statuses)
        Console.WriteLine("{0}: {1}",
            status.Element("user").Element("screen_name").Value,
            status.Element("text").Value);

    // update your Twitter status
    string newStatus = "writing my first HttpClient app";
    HttpUrlEncodedForm form = new HttpUrlEncodedForm();
    form.Add("status", newStatus);
    System.Net.ServicePointManager.Expect100Continue = false;
    resp = http.Post("update.xml", form.CreateHttpContent());
    resp.EnsureStatusIsSuccessful();
}
catch (Exception ex)
{
    Console.WriteLine(ex.Message);
}

Presentations from 2009 Microsoft SOA/BPM Conference Available Online

Presentations from 2009 Microsoft SOA/BPM Conference Available Online

Hadn’t noticed this before, but found the complete collection of videos and presentations from this year’s SOA & BPM Conference.  I didn’t make it up to Redmond for this, so it’ll be nice to peruse the content which covers topics such as:

Customer case studies
Designing services for “Dublin”
Using BAM for Service and SLA monitoring
Supporting WS*, REST […]

WCF REST Starter Kit Preview 2 is on CodePlex

WCF REST Starter Kit Preview 2 is on CodePlex

Go get it here.  This release is significant because they've finally provided a bunch of client-side features through a new generic REST client API called HttpClient.  It makes consuming real-world REST services much easier in .NET.  I've got several screencasts coming shortly.

Preview 1 focused on providing server-side features for building RESTful services while Preview 2 is focused on providing equally compelling client-side features.  The following paragraphs outline these differences (from the CodePlex site):

WCF REST Starter Kit Preview 1

The first set of features in the starter kit is server-side features for building WCF REST services, which enable or simplify various aspects of using the REST capabilities in WCF. These include declarative caching, security, error handling, help page support, conditional PUT, push style streaming, type based dispatch and semi-structured XML support. This functionality is exercised by a set of Visual Studio templates for creating REST services such as an Atom Feed service, a REST-RPC hybrid service, a resource singleton or collection service, and an Atom Publishing Protocol service.

WCF REST Starter Kit Preview 2

Preview 2 of the starter kit introduces a second set of client-side features for accessing WCF and third-party REST services from within .Net applications. The new HttpClient class provides the REST developer with a uniform extensible model for sending HTTP requests and processing HTTP responses, in a variety of formats. The new "Paste Xml as Type" Visual Studio add-in enhances the serialization support in HttpClient by generating serializable types based on XML examples or XSD schema.

Preview 2 only made a few minor changes to the Preview 1 server-side features.  The biggest changes were: 1) moving the code from the Service.svc.base.cs file into Microsoft.ServiceModel.Web.SpecializedCollections within the assembly, and 2) moving the REST templates so they now show up as “official” templates (e.g., they're no longer under My Templates). Other than that, the server side features remain the same for now.

I've done a bunch of screencasts on Preview 1 that you can find in the Pluralsight screencast library.  New ones on Preview 2 are coming soon.

New version of the REST starter kit

New version of the REST starter kit

Its available now on Codeplex 
– I showed off both the client and server pieces of the starter kit at my full-day
REST seminar at SDWest this week.   There are some very useful features
in the kit like:

  • WebProtocolException and an IErrorHandler implementation that returns correct error
    codes

  • The HttpClient class and the “Paste as Xml Serializable” feature to help minimize
    the work necessary when building RESTful clients

Those are just two of my favorites but there are a lot more.  I’ll be using the
HttpClient to help do Conditional GET when I do my Caching in REST talk next Friday
at Mix! 
If you are going to be in Vegas – some by and say hello.



Check out my new book on REST.

ESB Configuration Tool Not Working in the ESB Source Install?!

When you install ESB 2.0 guidance from the source (CTP Build 1), the ESB Configuration tool does not compile. This means that in order to configure the Databases and Web Services, you have to manually configure each of these sections by hand. When trying to compile the ESBConfigurationTool solution, the error you get is here:

The issue is that the DirectoryObjectPicker C# Class library project is referencing an Interop assembly named ActiveDs.dll. This assembly, in this build, does not have the correct signature. To circumvent this issue, one option is to try to refresh this interop assembly by re-referencing the Active DS Type Library as show here:

By doing this, an interop assembly is created using the .NET Framework SDK utility called TlbImp.exe. This process invokes the utility to create an interop assembly. However, this assembly that is created by the TlbImp utility is not signed by default.

You may be asking, "what does have to do with the DirectoryObjectPicker project?"

It just so happens that the DirectoryObjectPicker project needs to be signed and eventually installed into the GAC. Any project that needs to be signed and installed into the GAC has a constraint that says any referenced assemblies also need to be signed as well. We reach the real problem here. The original ActiveDs.dll is not signed correctly and the one created by re-referencing and using the Utility is not signed at all. There are ways in which we could just force a signature on an interop assembly, but we should not because we would be, in effect, “spoofing” the assembly. We should use the original manufacturer’s signature and use its interop version of the assembly.

Here’s the fix. Search your Root drive, and look for any file with the name ActiveDs. Chances are that you have installed other libraries or frameworks that use this fairly common assembly. It can be found inside the BizTalk Accelerators, WCF LOB adapter pack, and other .NET Frameworks. The one that worked for me is the Interop.ActiveDS.dll located inside the BizTalk RossettaNet Accelerators A4RN Msi folder:

Once you’ve found the right match, copy this assembly and place it into your DirectoryObjectPicker source folder. Add a reference to this assembly instead.

What you’ll notice at this point is that the project still doesn’t compile. The reason is because the namespaces are not quite correct. Compile the project and inside the source code file (NameTranslator.cs to be specific), where the few errors occur, add a using statement such as this:

using ActiveDs  = Interop.ActiveDS;

Adding this line of code will create a Namespace alias that points to the correct namespaces. Compile the project and remove the delay signing on each of the two projects: (DirectoryObjectPicker, EsbConfigurationTool). Build and install the DirectoryObjectPicker project into the GAC, and run the EsbConfigurationTool. You’re done.

Happy ESB'ing!