Reviews can now be embedded

I was going to make this feature available to only people that are logged in, but then realized that it probably doesn’t make sense to limit my exposure. Embed away!

The code goodies follow. ReviewHtml.GetReview() simply builds a bunch of javacript document.write() methods.

[ServiceContract]
public interface IContentService
{
[OperationContract]
[WebGet(UriTemplate = “review/{reviewId}”, BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat=WebMessageFormat.Xml)]
Stream GetReview(string reviewId);
}

public class ContentService : IContentService
{
public Stream GetReview(string reviewId)
{
return new MemoryStream(Encoding.UTF8.GetBytes(ReviewHtml.GetReview(new Guid(reviewId))));
}
}

Here are some interesting things I learned:
– I had to return the text as a stream rather than as text. If you return it as just a string, then there’s always sometype of serialization wrapper around it. Additionaly, the generated html tags get encoded. So, we get <td> instead

.

– In the UriTemplate, you specify the parameters.

UriTemplate = “review/{reviewId}”

Its maps the value in {reviewId} to the reviewId parameter of the method. That’s cool; very MVCish. Unlike MVC, however, it must be a string. In this case, the ID is a guid, but the mthod must accept a string.

I find this dissapointing and, if I had to guess, I’d say that will change. The framework is certainly capable of converting known types for us.

I really just sort of tripped through the WCF stuff in this case. I have to read up on the new REST capabilities.

Advertisements

One Response to Reviews can now be embedded

  1. Chris, Certified Scrum Master says:

    Really big fan of what you been doing lately. The embedded stuff looks great on my blog

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: