Ticket T594017
Visible to All Users

How to use the custom CommittingDelegate with the new WcfXafServiceHost

created 7 years ago

[DevExpress Support Team: CLONED FROM T570966: How to migrate to the new Middle-Tier implementation after upgrading to XAF v17.2+]
Hello,

I'm trying to move my application to the new WcfXafServiceHost, however I noticed there seems to be no apparent replacement for the EventHandler<DataServiceOperationEventArgs> comittingDelegate that was available in the SecuredDataServer constructor.

This was my previous call:

C#
var securedDataServer = new SecuredDataServer(dataLayer, securityProviderHandler, DevExpress.ExpressApp.MiddleTier.Logger.Instance, myCommittingDelegate, false);

This is the constructors signature:

C#
public SecuredDataServer(IDataLayer dataLayer, QueryRequestSecurityStrategyHandler querySecurityEnvironmentHandler, ILogger logger, EventHandler<DataServiceOperationEventArgs> committingDelegate, bool allowICommandChannelDoWithSecurityContext) {...}

Is there any way to include the myCommittingDelegate with the new WcfXafServiceHost?

Answers approved by DevExpress Support

created 7 years ago

Hello Christoph,

You are right. The new WcfXafServiceHost has no constructor with the CommittingDelegate parameter. Now you can add a custom Committing delegate in the following way:

  1. Create a descendant of the WcfSecuredServer class and override the GetSerializableObjectLayer method
C#
using DevExpress.ExpressApp.Security.ClientServer; using DevExpress.Xpo; using System.ServiceModel; ... public class CustomWcfSecuredServer : WcfSecuredServer { public CustomWcfSecuredServer(IDataLayer dataLayer, IDataServerSecurity serverSecurity, bool allowICommandChannelDoWithSecurityContext, InstanceContextMode contextMode) : base(dataLayer, serverSecurity, allowICommandChannelDoWithSecurityContext, contextMode) { } private void CommittingDelegate(object sender, DataServiceOperationEventArgs args) { // write your code here } protected override IMiddleTierSerializableObjectLayer GetSerializableObjectLayer() { IMiddleTierSerializableObjectLayer objectLayer = base.GetSerializableObjectLayer(); if (objectLayer is MiddleTierSerializableObjectLayer) { ((MiddleTierSerializableObjectLayer)objectLayer).Committing += CommittingDelegate; } return objectLayer; } }
  1. Create a descendant of the WcfXafServiceHost class and override the GetInstanceCore method
C#
using DevExpress.ExpressApp.Security.ClientServer; using System; using DevExpress.Xpo; using System.ServiceModel; using System.ServiceModel.Channels; ... public class CustomWcfServiceHost : WcfXafServiceHost { public CustomWcfServiceHost(string connectionString, Func<IDataServerSecurity> dataServerSecurity) : base(connectionString, dataServerSecurity) { } protected override object GetInstanceCore(InstanceContext instanceContext, Message message, IDataLayer dataLayer, IDataServerSecurity serverSecurity, bool allowICommandChannelDoWithSecurityContext, InstanceContextMode contextMode) { return new CustomWcfSecuredServer(dataLayer, serverSecurity, allowICommandChannelDoWithSecurityContext, contextMode); } }
  1. Replace the WcfXafServiceHost constructor call with a CustomWcfServiceHost constructor call in the Program.cs file of your server application
C#
WcfXafServiceHost serviceHost = new CustomWcfServiceHost(connectionString, dataServerSecurityProvider);

Let me know in case of any further difficulties.

    Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

    Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.