Step 2: Setting up your Project to use the WCF Data Service

Follow these instructions to allow your project to use the WCF Service for data access.

  1. In the Solution Explorer, right-click your Business Object project and select Add Reference... from the shortcut menu. In the Add Reference dialog under the .NET tab, scroll down and select the MM .NET Framework WCF assembly, then click OK:

  2. In the Solution Explorer, right-click your Windows or Web Forms project and select Add Reference... from the shortcut menu. In the Add Reference dialog under the .NET tab, scroll down and select the MM .NET Framework WCF assembly again, but before continuing, also, select the System.ServiceModel assembly then click OK:

  3. Now double-click your Windows or Web Forms Factory.cs or Factory.vb file and add code to override the CreateDataAccessSql() method (if you are using Oracle, override the CreateDataAccessOracle() method, and so on). Also add the using or Imports statements shown at the top of each code sample. Notice this code is checking the mmAppBase.DefaultDataAccessMode property to determine whether to run the default base code that instantiates a regular data access class or a WCF Service data access class. In the constructor of the WCF Service proxy class, you can pass the name of the end point which can be stored in your application configuration file:

    For example, in C#:

    using System.ServiceModel;
    using OakLeaf.MM.Main;
    using OakLeaf.MM.Main.Data;
    
    public class Factory : mmFactoryDesktop
    {
    	public override mmDataAccessSql CreateDataAccessSql()
    	{
    		if (mmAppBase.DefaultDataAccessMode == mmDataAccessMode.Local)
    		{
    			return base.CreateDataAccessSql();
    		}
    		else
    		{
    			// Get the Endpoint address
    			string DefaultEndpointNameSetting = AppDesktop.AppSettingsMgr.GetSetting("DefaultEndpointName");
                               
    			return new mmDataAccessWCFSql(DefaultEndpointNameSetting);
    		}
    	}
    }

    And in VB .NET:

    Imports System.ServiceModel;
    Imports OakLeaf.MM.Main
    Imports OakLeaf.MM.Main.Data
    
    Public Class Factory
       Inherits mmFactoryDesktop
       
       Public Overrides Function CreateDataAccessSql() As mmDataAccessSql
          If mmAppBase.DefaultDataAccessMode = mmDataAccessMode.Local Then
    		Return MyBase.CreateDataAccessSql()
          Else
    		Dim DefaultEndpointNameSetting As String = AppDesktop.AppSettingsMgr.GetSetting("DefaultEndpointName")
    		Return New mmDataAccessWCFSql(DefaultEndpointNameSetting)
          End If
       End Function
    
    End Class

  4. In your project's app.config file, add the following setting in the AppSettings section:

    <!-- Specifies the data Access Binding to use
              to be either NetTcp or WsHttp     
    -->
    <add key="DefaultEndpointName" value="tcpEndpoint"/>

    With this configuration in place, your applicaton configuration file can have an endpoint with security and one without and even switch between them. When the ChannelFactory is provided an endpoint name, it just uses the configuration for that endpoint

    <system.serviceModel>
        <client>
          <endpoint name="httpEndpoint"
                    address="http://192.168.101.125:8080/PW_Service/http"
                    binding="wsHttpBinding"
                    bindingConfiguration="wsHttpConfiguration"
                    contract="OakLeaf.MM.Main.ImmWCFDataService" />
          <endpoint name="tcpEndpoint"
                    address="net.tcp://192.168.101.125:8081/PW_Service"
                    binding="netTcpBinding"
                    bindingConfiguration="netTcpConfiguration"
                    contract="OakLeaf.MM.Main.ImmWCFDataService" />
        </client>
        <bindings>
          <wsHttpBinding>
            <binding name="wsHttpConfiguration" sendTimeout="00:05:00">
              <security mode="None" >
                <transport clientCredentialType="None" />
                <message clientCredentialType="None" />
              </security>
            </binding>
          </wsHttpBinding>
          <netTcpBinding>
            <binding name="netTcpConfiguration" sendTimeout="00:05:00" >
              <security mode="None">
                <transport clientCredentialType="None" />
                <message clientCredentialType="None" />
              </security>
            </binding>
          </netTcpBinding>
        </bindings>
      </system.serviceModel>


© (c) 2026 Oak Leaf Enterprises, Inc., 1996-2026 • Updated: 04/21/17
Comment or report problem with topic