Friday, March 11, 2011

Consuming WCF RIA Services from a Windows Phone 7

Visual Studio 2010 has come a long way, I love the tool, but when it comes to consuming a WCF RIA Service from a WP7 the experience is a little rough, to say the least.  The process becomes frustrating when the client is required to authenticate in order to use an operation contract.  This post will describe some of the pains that I went through and the workarounds that I used.

GETTING STARTED: Download the latest Silverlight 4.0 Tooolkit  By the time of this port I used the February 2011.  You can get the latest toolkit from codeplex following this link:  silverlight.codeplex.com/releases

ADD REFERENCE TO SILVERLIGHT PROJECT:  Microsoft.ServiceModel.DomainServices.Hosting.dll C:\Program Files (x86)\Microsoft SDKs\RIA Services\v1.0\Toolkit\Libraries\Server\Microsoft.ServiceModel.DomainServices.Hosting.dll

MODIFY WEB.CONFIG
Windows Phone 7 supports a specialized version of Silvelright 3, therefore it does not support all version of WCF endpoints/bindings but it does support WS-HTTP. For this reason, for WP7 to access a WCF RIA Service the only endpoint required is the SAOP endpoint. You can copy and paste in your the following into your web.config:







ADD A SERVICE REFERENCE TO YOUR WP7 PROJECT
If I have added the my service into a directory named Services of my Silverlight application and the namespave looks like this:
namespace PatrolCenter.Web.Services
{
// using

[EnableClientAccess()]
public class RidePlanService : LinqToEntitiesDomainService
{
...

Then the URI would be like this:

< namespace_of_ria_service >-< classname_of_your_ria_service >.svc where “.” are replaced with “-“.


Save and build.  In the case that you get errors, try closing Visual Studio and starting it again.  If everything goes "OK" then click the "All Files" button in solution explorer and expand the newly added WCF RIA Service.  It should look similar to this image:

In the case that the "Reference.svcmap" is empy then this is an indication that errors need to be corrected.  This is probably the most frustrating part because no obvious errors are issued.

No comments:

Post a Comment

A1 Repo: Simple Pagination for WCF Service Operation

It is never a good idea to paginate on the client.  This post is about a simple pagination for a WCF service operation.  For this work I nee...