WCF RIA Services Binding Deep dive

Note: This is based on WCF RIA Services beta, and some stuffs can change in a future release.

As many of you may know, WCF RIA Services uses WCF. WCF uses EndPoints where we specify the ABC (Address, Binding and Contract). By default WCF RIA Services uses its own ServiceHost, call DomainServiceHost. The DomainServiceHost will add EndPoints programmatically and it will add three kind of EndPoints, WebHttpBinding (for REST), BasicHttpBinding and BinaryHttpBinding. All binding will have a MaxReceivedMessageSize set to ”2147483647”. The address of the three default bindings added are the following:

For WebHttpBinding: “baseAddress" (REST with JSON Endpoint)

For BasicHttpBinding: “baseAddress” + “/soap” (SOAP with XML Endpoint)

For BinaryHttpBinding: “baseAddress” + “/binary” (SOAP with Binary Endpoint)

If you want to change the binding used, you can pass the address with any of the above prefix after the baseAddress to the constructor when you create the DomainContext on the client-side:

 var myDomainContext = MyDomainContext(
     new Uri("SilverlightApplication1-Web-MyDomainService.svc/binary", UriKind.Relative)));


The security mode used on the bindings are “Transport” for https and the rest if a credential exists is “Transport credential only”. What's worry me is that the Metadata behavior’s HTTP get is enabled, so everyone can get information about the DomainService. Because of security reasons when using WCF, it’s advisable to turn it off in production.

WCR RIA Services uses a DomainServiceHostFactory which inherits from the SerivceHostFactory. The DomainServiceHostFactory has the following method:

protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
{
return new DomainServiceHost(serviceType, baseAddresses);
}


The serviceType is the type of the service and the baseAddresses are an array of addresses which will be added as addresses to EndPoints. We can create our own ServiceHost if we want, or just create our own SerivceHost factory to just add more EndPoints for specific addresses, or filter out some addresses we don’t want to allow. If we creates our own ServiceHost, we need to inherits the ServiceHost base class, and also create our own ServiceHostFactory. Here is an example of a ServiceHostFacotry which will return a custom ServiceHost:

public class MyDomainServiceHostFactory : ServiceHostFactory
{
public MyDomainServiceHostFactory() {}

protected override ServiceHost CreateServiceHost(
Type serviceType,
Uri[] baseAddresses)
{
return new MyDomainServiceHost(serviceType, baseAddresses);
}
}


The MyDomainServiceHost could for example look like this:

public class MyDomainServiceHost : DomainServiceHost
{
public MyDomainServiceHost(
                      Type domainServiceType,
                      params Uri[] baseAddresses) : base(
                                                     domainServiceType;
baseAddresses)
{
}



 

 


protected override void AddEndpoints()
{
//...

base.AddServiceEndPoint(...);
}
}


Note: The DomainServiceHost, is the WCF RIA’s own custom ServiceHost.

We can then use our custom ServiceHostFactory by adding a .svc file to for our DomainServices to the Services directory (If you don’t have a Services directory in the root folder of your web project, just add one) and specify a Factory by using the Factory attribute of the ServiceHost directive:

<%@ ServiceHost Service="SilverlightApplication1.Web.MyDomainService"
Factory="SilverlightApplication1.Web.MyDomainServiceHostFactory" %>


To get the name of the .svc file, you simply use the type of the DomainSerivce and replace “.” with a “-”. So if the type is as above “SilverlightApplication1.Web.MyDomainService”, the .svc file should have the following name: “SilverlightApplication1-Web-MyDomainService.svc”.

If you want to know when I post new blog posts, you can follow me on twitter: http://www.twitter.com/fredriknormen

Published Friday, November 27, 2009 2:26 AM by Fredrik N

Comments

# Twitter Trackbacks for WCF RIA Services Binding Deep dive - Fredrik Norm??n [asp.net] on Topsy.com

Pingback from  Twitter Trackbacks for                 WCF RIA Services Binding Deep dive - Fredrik Norm??n         [asp.net]        on Topsy.com

# Interesting Finds: November 27, 2009

Friday, November 27, 2009 8:39 AM by Jason Haley

Interesting Finds: November 27, 2009

# Dew Drop &ndash; November 27. 2009 | Alvin Ashcraft&#039;s Morning Dew

Pingback from  Dew Drop &ndash; November 27. 2009 | Alvin Ashcraft&#039;s Morning Dew

# Daily tech links for .net and related technologies - November 28-30, 2009

Sunday, November 29, 2009 2:28 AM by Sanjeev Agarwal

Daily tech links for .net and related technologies - November 28-30, 2009 Web Development Main Differences

# WCF RIA Service – How to configure the WCF Service maximum items returned by the Query

Saturday, December 19, 2009 3:44 AM by Fredrik Normén

Note: This is post is based on the WCF RIA Services Beta for VS 2008 and changes can be done before WCF

# WCF RIA Service – How to configure the WCF Service maximum items returned by the Query

Saturday, December 19, 2009 3:54 AM by Cornerstones utvecklarblogg

Note: This is post is based on the WCF RIA Services Beta for VS 2008 and changes can be done before WCF

# #Silverlight WCF RIA Services Binding http://weblogs.asp.net/fredriknormen/archive/2009/11/27/wcf-ria-services-binding-deep-dive.aspx

Tuesday, December 22, 2009 12:17 PM by Twitter Mirror

#Silverlight WCF RIA Services Binding http://weblogs. asp.net /fredriknormen/archive/2009/11/27/wcf-ria

# re: WCF RIA Services Binding Deep dive

Tuesday, January 05, 2010 10:25 AM by Josip Jaić

Hi,

I had problem with my silverlight app. I am using many services and one of them did not work (huge dataset)

Only thing that helped me is putting this attribute;

[AspNetCompatibilityRequirements ( RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed )]

   [ServiceBehavior ( MaxItemsInObjectGraph = 2147483647 )]

   [EnableClientAccess ( )]

   public class AktivnostOpisDomainService : DomainService

   {

# re: WCF RIA Services Binding Deep dive

Monday, July 19, 2010 7:45 AM by Rogier van de Roer

Hi there,

In my version of RIA Services (1.0) the DomainServiceHost has no AddEndpoints() method to override.

What version is this based on?

# Silverlight????????????WCF???binding?????? &raquo; NoName

Saturday, June 18, 2011 9:56 PM by Silverlight????????????WCF???binding?????? » NoName

Pingback from  Silverlight????????????WCF???binding?????? &raquo; NoName

# Silverlight limited support the binding problem WCF

Sunday, July 17, 2011 2:54 AM by Silverlight limited support the binding problem WCF

Pingback from  Silverlight limited support the binding problem WCF

# Silverlight limited support the binding problem WCF

Saturday, August 20, 2011 2:20 AM by Silverlight limited support the binding problem WCF

Pingback from  Silverlight limited support the binding problem WCF

Leave a Comment

(required) 
(required) 
(optional)
(required)