Using different WCF Bindings with Enterprise Core Objects – ECO – the model driven framework

There are already numerous ways to set up an Eco-based system. Besides having a multitude of PersistenceMappers that enables Object-relational mapping for the most popular databases – Eco also provides a Bridged communication between an Eco-client and an Eco-server. Since Eco6 this is performed by the EcoPersistenceClientWCF (client) and the EcoPersistenceMapperProviderWCF (server).

What this bridge actually does is to handle all server communication in terms of queries, fetches, lazy loading, updating and refreshing over an xml based format we call DataBlock. Several advantages come from using this client server bridge rather than having the clients hook up with the server based database by itself:

The client does not need to know anything about the database being used – hence no  distribution of Client-db-communication-setups.

The server does not need to expose the database for client calls and thus invite attacks from all the suckers out there.

The Server is able to provide you with an efficient Refresh mechanism that easily can be set up to synchronize all the clients.

Since Eco6 the bridge is implemented with WCF – before Eco6 this was implemented with .net Remoting – but WCF is much more flexible and configurable and better in everyway.

Eco creates a BasicHttpBinding if nothing else is configured. This is a quick way to get things going – but of course many situations call for better security, less overhead and/or authentication that is easily achieved with WCF. Maybe you want to create your own binding implementation to solve some business requirement and WCF is good for that too.

I added a sample, EcoProjectWCF_NET_TCP_Binding to show how to configure different bindings than the standard BasicHttpBinding.

image

The client’s – WCF Settings

The client has an App.Config that can be left empty – but in this sample it looks like this:

Code Snippet
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <configuration>
  3.   <system.serviceModel>
  4.  
  5.     <client>
  6.       <endpoint name="TheEndPoint"
  7.                 address="net.tcp://localhost:8001/EcoProject33WinFormServer"
  8.                 binding="netTcpBinding"
  9.                 contract="Eco.Wcf.Common.IPersistenceMapperWCF">
  10.         <!–Include the identity element when running cross-machine in a domain.–>
  11.         <!–
  12.         <identity>
  13.           <userPrincipalName value = "user_name@service_domain"/>
  14.         </identity>
  15.         –>
  16.       </endpoint>
  17.  
  18.       <endpoint name="SomeOtherEndPoint"
  19.             address="http://localhost:8001/EcoProject33WinFormServer"
  20.             binding="basicHttpBinding"
  21.             contract="Eco.Wcf.Common.IPersistenceMapperWCF"></endpoint>
  22.       </client>
  23.  
  24.   </system.serviceModel>
  25. </configuration>

It defines a named EndPoint “TheEndPoint”, it defines the binding as netTcpBinding and it has the IPersistenceMapperWCF contract. This Contract is the same for every Eco client server bridge.

Also note the Address that points out the server – we need to make sure that the server is available at that address – server configuration is explained in the next section.

In the EcoSpace, that is shared by the client and the server but nevertheless the place to define the client persistence mapper, we have added the PersistenceMapperWCFClient. In order to use the setting from the App.Config we set the EndpointConfigurationName to the one used in the config : “TheEndPoint”. Done. Client is all set.

image

When the EndpointConfigurationName is set, the PersistenceMapperWCFClient component ignores the Uri setting. The Uri setting is only there to give an address to the server for the default BasicHttpBinding, also the MaxReceivedMessageSize setting is ignored since this is better defined on the binding in the App/Web.Config.

The server’s – WCF Settings

Also the server has an App.Config – if your server is hosted by IIS then it is a web.config but the content is the same:

Code Snippet
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <configuration>
  3.   
  4.   <system.serviceModel>
  5.      
  6.     <services>
  7.       <service name="EcoProject33.EcoProject33PMPWCF"
  8.                behaviorConfiguration="ServiceBehavior">
  9.         <endpoint address=""
  10.                   behaviorConfiguration=""
  11.                   binding="netTcpBinding"
  12.                   bindingConfiguration="TheTCPBinding"
  13.                   contract="Eco.Wcf.Common.IPersistenceMapperWCF">
  14.         </endpoint>
  15.       </service>
  16.     </services>
  17.     
  18.     <bindings>
  19.       <!–  Following is the expanded configuration section for a NetTcpBinding.
  20.             Each property is configured with the default values.
  21.             See the Message Security, and Transport Security samples in the WS binding samples
  22.             to learn how to configure these features.  –>
  23.       <netTcpBinding >
  24.         <binding name="TheTCPBinding"
  25.                  closeTimeout="00:01:00"
  26.                  openTimeout="00:01:00"
  27.                  receiveTimeout="00:10:00"
  28.                  sendTimeout="00:01:00"
  29.                  transactionFlow="false"
  30.                  transferMode="Buffered"
  31.                  transactionProtocol="OleTransactions"
  32.                  hostNameComparisonMode="StrongWildcard"
  33.                  listenBacklog="10"
  34.                  maxBufferPoolSize="524288"
  35.                  maxBufferSize="65536"
  36.                  maxConnections="10"
  37.                  maxReceivedMessageSize="65536">
  38.           <readerQuotas
  39.             maxDepth="32"
  40.             maxStringContentLength="8192"
  41.             maxArrayLength="16384"
  42.             maxBytesPerRead="4096"
  43.             maxNameTableCharCount="16384"/>
  44.           <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false"/>
  45.  
  46.           <security mode="Transport">
  47.             <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign"/>
  48.           </security>
  49.           
  50.         </binding>
  51.       </netTcpBinding>
  52.     </bindings>
  53.  
  54.     <!–For debugging purposes set the includeExceptionDetailInFaults attribute to true–>
  55.     <behaviors>
  56.       <serviceBehaviors>
  57.         <behavior name="ServiceBehavior">
  58.           <serviceDebug includeExceptionDetailInFaults="false" />
  59.         </behavior>
  60.       </serviceBehaviors>
  61.     </behaviors>
  62.   </system.serviceModel>
  63. </configuration>

This config file defines the Service. The name is important and is unique for each ECO project you create – it is the class of the WCF stub that you will find in the <projectname>PMP.cs file:

Code Snippet
  1. /// <summary>
  2. /// This class is used to register the WCF server portion of a PersistenceMapperProvider
  3. /// </summary>
  4. public class EcoProject33PMPWCF : PersistenceMapperProviderWCF<EcoProject33PMP>
  5. {

The contract in the config endpoint will always be the same: Eco.Wcf.Common.IPersistenceMapperWCF

A good feature is that you can add several endpoints to your service – so that you can have multiple types of clients that communicate in different ways. Silverlight does not support all that many Bindings (not our fault) so Silverlight clients need to talk over http. But if you have in-house clients or ASP.NET servers on the safe side of the firewall you will want something more efficient most likely.

The last thing to configure for the server in this sample is to call Register with an Address:

Code Snippet
  1. public void RegisterServer()
  2. {
  3.     lblStatus.Text = "Server status: Started " + DateTime.Now.ToString();
  4.  
  5.     
  6.     host = EcoProject33.EcoProject33PMPWCF.Register("net.tcp://localhost:8001/EcoProject33WinFormServer");
  7. }

This entry was posted in WCF. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*