Silverlight 4 + RIA Services - Ready for Business: Exposing WCF (SOAPWSDL) Services

Continuing in our series, I wanted to touch on how a RIA Services can be exposed as a Soap\WSDL service.   This is very useful if you want to enable the exact same business logic\data access logic is available to clients other than Silverlight.    For example to a WinForms application or WPF or even a console application.  SOAP is a particularly good model for interop with the Java\JEE world as well. 

 

First you need to add a reference to Microsoft.ServiceModel.DomainSerivves.Hosting.EndPoints assembly from the RIA Services toolkit. 

 

image

 

Then you need to edit the endpoints section of the domainserivces config in web.config  file.  Below I am showing the SOAP and OData endpoints enabled. 

 

   <system.serviceModel>
     <domainServices>
       <endpoints>
         <add name="OData" 
              type="System.ServiceModel.DomainServices.Hosting.ODataEndpointFactory, System.ServiceModel.DomainServices.Hosting.OData, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
         <add name="Soap"
              type="Microsoft.ServiceModel.DomainServices.Hosting.SoapXmlEndpointFactory, Microsoft.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
       </endpoints>
     </domainServices>
  
  
  

 

Now, all you have to do is navigate in the browser to this URL:

https://localhost:21516/BusinessApplication1-web-DishViewDomainService.svc

Note the pattern is [namespace]-[typename].svc

image

And we get the very familiar WCF service debug page.

And if you really want to drill in, here is the full WSDL describing the service.

image

 

You are done on the server, now let’s look at how you consume that on the client.    For the sake of simplicity, I have created a new Console application.  Right click on the project and select Add Services Reference.

image

 

image

   1: var context = new DishViewDomainServiceSoapClient();
  2: var results = context.GetRestaurants();
  3: foreach (var r in results.RootResults)
  4: {
  5:    Console.WriteLine(r.Name);
  6: }
  7: 

 

The code for query is very simple.  Line 1 creates the client proxy, line 2 does a synchronous call to the server. Then we simply loop through the results.

 

image

 

Updating the data is a little bit more interesting…    I need to create a ChanageSet that I populate with any updates. in this case I am updating just one value.  I also need to send the original value back to the server. 

   1: var changeSet = new ChangeSetEntry();
  2: var org = new Restaurant();
  3: org.ID = entity.ID;
  4: org.Name = entity.Name;
  5: entity.Name = "Updated:" + entity.Name;
  6: changeSet.Entity = entity;
  7: changeSet.OriginalEntity = org;
  8: changeSet.Operation = DomainOperation.Update;
  9: var updateResults = context.SubmitChanges(new ChangeSetEntry[] { changeSet });
 10: 

 

 

And you can see the result of running this a couple of times:

image

 

For more information, see Deepesh’s post on Configuring your DomainService for a Windows Phone 7 application

 

For V1.0, this post describes the RIA Services story for WPF applications.  While it works, it is clearly not the complete, end-to-end solution RIA Services offers for Silverlight.   For example, you may want the full experience:  the DataContext, entities with validation, LINQ queries, change tracking, etc.  This level of support for WPF is on the roadmap, but will not make V1.  But if you like the RIA Services approach, you might consider DevForce from IdeaBlade or CSLA.NET which works for both WPF and Silverlight.   The great folks at IdeaBlade have offered me 10 free licenses to give out.  If you are interested in one, please let me know.

Comments

  • Anonymous
    March 29, 2010
    Brad Are we creating here a new endpoint to the service (soap), or just exposing the metadata of the format already used? If this is a new endpoint, then how can we just expose the metadata of the default message format?

  • Anonymous
    March 29, 2010
    @Yaron -- Correct, this just exposes the metadata for the default endpoint so that any client can access it.  

  • Anonymous
    March 29, 2010
    Hello Brad, I would love to have free license of DevForce for my development and experimentation. ivan@mammothmicro.com Thanks

  • Anonymous
    March 29, 2010
    @Ivan -- Great, I got you connected!  You should hear something soon.

  • Anonymous
    March 29, 2010
    Brad, Me too also intrested in Ideablade license. You can reach me on afzal@maqinfotech.com

  • Anonymous
    March 29, 2010
    CSLA.Net == California State Library Association web site. :) Thanks for your awesome series(es) on RIA!

  • Anonymous
    March 29, 2010
    @Craig -- thanks, fixed!

  • Anonymous
    March 29, 2010
    Brad, thanks for the continuing your posts. I'd love to have an Ideablade license also.  I can reached at balukumber@hotmail.com.

  • Anonymous
    March 29, 2010
    My company already has a lot of existing WCF services.  Is there any easy way to expose those existing services as domain services, or would it require converting all of them to domain services (which realistically, we would never do because there are too many).  I would like to use the dynamic linq capability on our current services.

  • Anonymous
    March 29, 2010
    Free licenses for DevForce, Count me in! Its always our goal at my company (A huge civil engineering firm) to create apps as a service and consume the service in a UI. Sounds like RIA services is the ideal for this if your using Silverlight, but WPF and ASP.NET won't have all the fancy features. Hope this changes soon.

  • Anonymous
    March 29, 2010
    Free licenses for DevForce, Count me in! Its always our goal at my company (A huge civil engineering firm) to create apps as a service and consume the service in a UI. Sounds like RIA services is the ideal for this if your using Silverlight, but WPF and ASP.NET won't have all the fancy features. Hope this changes soon. wildert@gmail.vom

  • Anonymous
    March 29, 2010
    I'd certainly be interested in a free license from DevForce if you still have any left. Thanks for the great article I was just looking for something like this the other day. dfolger[@]addusa.com

  • Anonymous
    March 29, 2010
    Hi, how can I switch from binary to text encoding?

  • Anonymous
    March 30, 2010
    We are currently updating our client application from a mix of asp.net and silverlight (for media playback) to a full fledge SL4 (w OOB) application. RIA services definitively makes for our authentication and consuming data much easier though updates and generation of new entities still remains a little tricky mostly with the desire to offer these capabilities in offline scenarios. Would definitively be interested in DevForce licenses if you have any left as was considering their product, at least to evaluate if it meshed into our current architecture. Thanks for insights and conversations at MIX10, great learning by osmosis. nicolai.siggel [@] replayedu . com

  • Anonymous
    March 30, 2010
    If there are any licenses for DevForce left I would be interested as well - I have been following what Ward's company has been doing loosely for a while and we have some WPF apps internally at my company that would benefit from taking advantage from similar solutions to what RIA Services currently is offering for Silverlight.  I can be reached at HintonBR at ldschurch.org

  • Anonymous
    March 30, 2010
    Well, if there is any left, please count me in.  sguven [@] gmail . com

  • Anonymous
    March 30, 2010
    Nice post.  Would love to brush up my dev force skills on full license if you have one left.  Jbrantingham@gmail.com

  • Anonymous
    March 31, 2010
    Brad, I have questions here, as some of this described is  vague to me. ie. why are you showing adding the service reference to a console app vs. a Silverlight app ?  I don't understand how console apps fit this topic/title ? Basically, are you trying to say that by adding those two lines to my Silverlight config file that it will turn my WCF service references into Domain Service calls ? Sorry, missing the big picture here Brad.  I'm highly interested in consuming wcf services and using domain service together, so I'm interested... but confused by this post  :) email me if you want steven dot gentile at gmail dot com

  • Anonymous
    March 31, 2010
    @Ladislav  are you looking to switch to text for debugging?  if so, check out this post: http://blogs.msdn.com/saurabh/archive/2010/03/16/ria-services-application-deployment.aspx

  • Anonymous
    March 31, 2010
    Wow -- thanks for your interest in DevForce... I have given away all 10 of the license that they gave me.  If you got one of them, the DevForce guys should be contacting you shortly.  

  • Anonymous
    March 31, 2010
    Hi Brad, Is it possible to configure the exposed endpoint with other bindings, like with MSMQ, or with WS-i extensions like WS-Security, or policy?

  • Anonymous
    April 02, 2010
    Brad, Me too also intrested in Ideablade license. You can reach me on wangsan@keigen.net Thanks

  • Anonymous
    April 03, 2010
    Hello Brad, I'm interested in an Ideablade license as well. You can contact me at manuelfelicio{at}gmail[dot]com. Thanks

  • Anonymous
    April 06, 2010
    well,so i have no reference Microsoft.ServiceModel.DomainServices.Hosting.EndPoints in my reference windows.How can i bring that reference

  • Anonymous
    April 22, 2010
    Hi, Brad! Is it possibly to consume default raw REST endpoint  like WCF service? I cann't configure bindings :( it would be very nice of you to expain how it can be achieved.

  • Anonymous
    April 22, 2010
    The soap endpoint for WCF RIA domain service didnot support "Include/Association", after generate the service reference, the object with "include/association" attribute cannot be generated on the service reference side. Any solution?