As we are all aware DataPortal in CSLA serves as the backbone in implemeting SOA in CSLA. This allows our application business objects to be hosted in other server. The beauty of implementing this in CSLA is that no code change needed to be done in our business object. In this blog I will show how this can be achieved using a WCF hosted in IIS.
First this to do is to create a .svc file in your web project. In our case we will name our .svc file as WcfPortal.svc.
<%@ ServiceHost Language="C#" Debug="false" Service="Csla.Server.Hosts.WcfPortal" %>
As you can see, the value of service attribute is set to Csla.Server.Hosts.WcfPortal.
Next step is to set the following configuration in the web.config of your web project.
<system.serviceModel> <bindings> <wsHttpBinding> <binding name="wsHttpBindingSettings" closeTimeout="00:10:00" openTimeout="00:10:00" sendTimeout="00:10:00" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647" messageEncoding="Text" > <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> </binding> </wsHttpBinding> </bindings> <behaviors> <serviceBehaviors> <behavior name="WcfPortalBehavior"> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="false" /> </behavior> </serviceBehaviors> </behaviors> <services> <service name="Csla.Server.Hosts.WcfPortal" behaviorConfiguration="WcfPortalBehavior" > <endpoint address="" binding="wsHttpBinding" contract="Csla.Server.Hosts.IWcfPortal" bindingConfiguration="wsHttpBindingSettings" /> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> </service> </services> </system.serviceModel>
One of the most important stuff to check is the bindingConfiguration settings, in our example we set the value of the maxReceivedMessageSize to a very big value. this is to avoid exceptions regarding the limit of the size of the message sent across the channel. Due to the size of your business object some scenarios may exceed the default size set by Wcf.
On the client machine se the following configurations
<system.serviceModel> <bindings> <wsHttpBinding> <binding name="wsHttpBindingSettings" closeTimeout="00:10:00" openTimeout="00:10:00" sendTimeout="00:10:00" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647" messageEncoding="Text" > <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> </binding> </wsHttpBinding> </bindings> <client> <endpoint name="WcfDataPortal" address="http://localhost:52423/WcfPortal.svc" binding="wsHttpBinding" contract="Csla.Server.Hosts.IWcfPortal" bindingConfiguration="wsHttpBindingSettings"/> </client> </system.serviceModel>
That’s it! Happy coding