🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
WCF issues
This page was created by Hans.karlsen on 2018-05-07. Last edited by Wikiadmin on 2026-07-29.

You can diagnose and correct legacy WCF connectivity, message-size, and serialization problems between an ECO/MDriven client and a remote persistence server; use Documentation:WebApi for new communication implementations.

Scope and current direction

Windows Communication Foundation (WCF) is the legacy transport used by the ECO client-server bridge. The bridge uses a PersistenceMapperWCFClient on the client and an IPersistenceMapperWCF service on the server to send queries, fetches, updates, lazy-loading requests, and refreshes.

MDriven 7.2 drops WCF as a supported persistence-mapper communication channel and relies on WebApi. If you target .NET 6 or later, do not invest in a new WCF setup; follow Documentation:WebApi and use Documentation:PersistenceMapperWEBAPIClient instead. This page is for maintaining an existing WCF solution, typically on .NET Framework.

Diagnose a connection problem

Work through these checks in order. WCF failures can otherwise appear as a generic client error or an unexpected server shutdown.

1. Identify the server host

Determine whether the remote persistence server runs:

  • under IIS, where IIS creates and hosts the WCF service; or
  • as a self-hosted Windows service or Windows Forms application, where your code creates a ServiceHost.

This distinction determines where you configure bindings and message limits. Do not create a second ServiceHost for a service hosted by IIS.

2. Verify the client endpoint

Find every assignment to persistenceMapperClient.Uri in the client projects and check that each URL points to the running WCF service.

this.persistenceMapperClient1.Uri =
    "http://localhost:52150/EcoProjectWindowsPhone71PMPWCF.svc";

The service portion of the URL must correspond to the WCF service exposed by the persistence-server project. A client can have more than one generated or configured persistence mapper, so check every occurrence rather than changing only the first one you find.

If the client uses a named endpoint, the URI property is not the active setting. With EndpointConfigurationName set, PersistenceMapperWCFClient reads the endpoint address and binding from App.config or Web.config and ignores both Uri and its MaxReceivedMessageSize property. See using different WCF bindings for the endpoint configuration pattern.

3. Use an emulator-reachable address

localhost means the machine on which the client runs.

Client environment Address for a service running on the development PC
Windows Phone emulator localhost can be used; it resolves to the development PC in this emulator.
Android emulator Use 10.0.2.2 instead of localhost. For example, change http://localhost:52150/... to http://10.0.2.2:52150/....

4. Check required server access policy where applicable

If the affected client technology requires a ClientAccessPolicy.xml, place it at the web-server root. In IIS, the web-server root is not the application's virtual directory. This check is only relevant to clients and hosting scenarios that use such a policy.

5. Check authentication separately from reachability

A reachable endpoint can still reject a caller because of its authentication or authorization configuration. For an MDrivenServer installation using Windows Authentication, configure IIS authentication and the MDrivenServer WCF settings as described in HowTos:MDrivenServer with Windows authentication.

Configure message limits

Large DataBlock transfers can exceed the default WCF binding limits. Configure matching limits on the binding used by the service; when a named client endpoint is used, configure its binding there as well.

Self-hosted remote persistence server

For a Windows service or Windows Forms remote persistence server, configure the BasicHttpBinding before adding the endpoint to the ServiceHost. The following example permits large messages and uses the maximum XML reader quotas.

BasicHttpBinding binding = new BasicHttpBinding();

binding.MaxReceivedMessageSize = maxReceivedMessageSize;
binding.ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max;
binding.MaxBufferSize = int.MaxValue;
binding.MaxBufferPoolSize = 0;

Uri address = new Uri(uri);
ServiceHost svc = new ServiceHost(t, address);
svc.AddServiceEndpoint(typeof(IPersistenceMapperWCF), binding, address);

IIS-hosted remote persistence server

For an IIS-hosted service, IIS provides the ServiceHost. Put the binding configuration in the application's Web.config and reference that binding from the service endpoint.

In this example, replace Frako.Emvis.PServerWebService.EmvisPMPWCF with the WCF stub class for your project. This is the subclass of PersistenceMapperProviderWCF<...> in the generated <projectname>PMP.cs file. The endpoint contract remains Eco.Wcf.Common.IPersistenceMapperWCF.

<system.serviceModel>
  <services>
    <service name="Frako.Emvis.PServerWebService.EmvisPMPWCF"
             behaviorConfiguration="TheBehavior">
      <endpoint address=""
                binding="basicHttpBinding"
                bindingConfiguration="TheBindingConfiguration"
                contract="Eco.Wcf.Common.IPersistenceMapperWCF" />
    </service>
  </services>

  <bindings>
    <basicHttpBinding>
      <binding name="TheBindingConfiguration"
               maxReceivedMessageSize="104857600">
        <readerQuotas maxStringContentLength="104857600" />
      </binding>
    </basicHttpBinding>
  </bindings>

  <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  <behaviors>
    <serviceBehaviors>
      <behavior name="TheBehavior">
        <serviceDebug includeExceptionDetailInFaults="true" />
        <dataContractSerializer maxItemsInObjectGraph="2147483646" />
      </behavior>
    </serviceBehaviors>
  </behaviors>
</system.serviceModel>

The bindingConfiguration value is the link between the endpoint and the named binding definition. If the names differ, the endpoint will not use the intended limits.

For named endpoints, alternate transports, multiple endpoints, and security settings, use Using different WCF Bindings with Enterprise Core Objects – ECO – MDriven framework rather than duplicating configuration here.

Register application-specific types

WCF must know every application-defined type transferred through the service. This commonly affects custom enumeration types used by model attributes. If the type is registered on only one side, a request may fail with an unexpected server shutdown instead of a useful client error.

Register the same types on both the server and the client before the WCF service or client performs communication.

IIS server: Global.asax

Add the types during application startup.

protected void Application_Start(object sender, EventArgs e)
{
    Eco.Wcf.Common.KnownTypesHelper.AdditionalTypes.Add(typeof(OrgeinheitTypEnum));
    Eco.Wcf.Common.KnownTypesHelper.AdditionalTypes.Add(typeof(ECObjectTypEnum));
}

Client: startup code

Add the same registrations before the client starts using its EcoSpace or persistence mapper.

static void Main()
{
    Eco.Wcf.Common.KnownTypesHelper.AdditionalTypes.Add(typeof(OrgeinheitTypEnum));
    Eco.Wcf.Common.KnownTypesHelper.AdditionalTypes.Add(typeof(ECObjectTypEnum));

    // Start the application after registering known types.
}

For example, if OrgeinheitTypEnum is the type of a model attribute sent in a DataBlock, add it on both sides. Do this for every custom enum or other application-defined attribute type that can cross the WCF boundary.

Turn on WCF diagnostic logging

Enable WCF diagnostic logging on the server when the endpoint, hosting model, binding, and known types appear correct but the request still fails. The log exposes exceptions that may be hidden behind a generic WCF failure.

  1. Create a folder that the server process can write to, for example C:\temp.
  2. Add the following system.diagnostics section to the server Web.config. For a self-hosted server, add it to the application configuration file.
  3. Reproduce the failing request.
  4. Open C:\temp\WCFTracelog.log and inspect the service-model exceptions and serialization errors near the failed request.
<configuration>
  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel"
              switchValue="Information, ActivityTracing"
              propagateActivity="true">
        <listeners>
          <add name="traceListener"
               type="System.Diagnostics.XmlWriterTraceListener"
               initializeData="c:\temp\WCFTracelog.log" />
        </listeners>
      </source>
    </sources>
  </system.diagnostics>
</configuration>

The application-pool identity must have write permission to the selected folder. If it does not, choose a writable path or grant the required permission; otherwise the diagnostic file will not be created.

When the trace identifies an unknown custom type, register that type with KnownTypesHelper.AdditionalTypes on both client and server, then restart the IIS application or self-hosted service so startup registration runs again.

See also