Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6006155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:29:57+00:00 2026-05-23T01:29:57+00:00

I am trying to have my WCF client receive info from a callback. I

  • 0

I am trying to have my WCF client receive info from a callback. I have created a Client Library that any WCF Client can use to connect to my WCF Service. I am uncertain if I should implement the Callback in the Client Library or the WCF Client itself.

I have attempted to create an event that will be fired by calling the OnNotification(...) method from within the callback. However, it cannot be called from within the Callback method and I’m not sure why.

Here is my Client Library used to connect to the WCF Service:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;  //needed for WCF communication

namespace DCC_Client
{
    public class DCCClient
    {
        private DuplexChannelFactory<ServiceReference1.IDCCService> dualFactory;

        public ServiceReference1.IDCCService Proxy;

        public DCCClient()
        {
            //Setup the duplex channel to the service...
            NetNamedPipeBinding binding = new NetNamedPipeBinding();
            dualFactory = new DuplexChannelFactory<ServiceReference1.IDCCService>(new Callbacks(), binding, new EndpointAddress("net.pipe://localhost/DCCService"));
        }

        public void Open()
        {
            Proxy = dualFactory.CreateChannel();
        }

        public void Close()
        {
            dualFactory.Close();
        }

        /// <summary>
        /// Event fired an event is recieved from the DCC Service
        /// </summary>
        /// <param name="e"></param>
        protected virtual void OnNotification(EventArgs e)
        {
            if (Notification != null)
            {
                Notification(this, e);
            }
        }
    }

    public class Callbacks : ServiceReference1.IDCCServiceCallback
    {
        void ServiceReference1.IDCCServiceCallback.OnCallback(string id, string message, Guid key)
        {
            //Can't call OnNotification(...) here?
        }
    }
}

OnNotification(...) cannot be called in the Callback method.

Here is an example of my how my WCF Client would be implemented using an EventHandler:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using DCC_Client;

namespace Client_Console_Test
{
    class Program
    {
        private static DCCClient DCCClient;

        static void Main(string[] args)
        {
            try
            {
                DCCClient = new DCCClient();

                DCCClient.Notification += new EventHandler(DCCClient_Notification);

                DCCClient.Open();

                DCCClient.Proxy.DCCInitialize();

                Console.ReadLine();
                DCCClient.Proxy.DCCUninitialize();

                DCCClient.Close();
            }
            catch (Exception e)
            {
                DCCClient.Log.Error(e.Message);
            }
        }

        static void DCCClient_Notification(object sender, EventArgs e)
        {
            //Do something with this event
        }
    }
}

Is this the correct way to pass the callback info to my WCF Client? I feel like adding an EventHandler is redundant and I should just use the callback itself. Am I correct to have implemented the Callback in my Client Library, or should this be done in each WCF Client?

Thank you in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T01:29:58+00:00Added an answer on May 23, 2026 at 1:29 am

    I think I figured it out. I simply need to pass the DCCClient reference to the callback, and then call OnNotification() from it.

    In DCC_Client:

    public class DCCClient
    {
        private DuplexChannelFactory<ServiceReference1.IDCCService> dualFactory;
    
        private Callbacks notificationCallback; //Add callback object here
    
        public ServiceReference1.IDCCService Proxy;
    
        public DCCClient()
        {
            //Setup the duplex channel to the service...
            NetNamedPipeBinding binding = new NetNamedPipeBinding();
    
            notificationCallback = new Callbacks(this); //Pass DCCClient reference here
    
            dualFactory = new DuplexChannelFactory<ServiceReference1.IDCCService>(notificationCallback, binding, new EndpointAddress("net.pipe://localhost/DCCService"));
        }
    
        //....
    
        public class Callbacks : ServiceReference1.IDCCServiceCallback
        {
            private DCCClient client;
    
            public Callbacks(DCCClient client)
            {
                this.client = client; //grab client refernce
            }
    
            void ServiceReference1.IDCCServiceCallback.OnCallback(string id, string message, Guid key)
            {
                client.OnNotification(n); //send the event here
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a client for a WCF service that I have hosted
I'm trying to get my head around the addressing of WCF services. We have
I'm having some problems with my WCF server and client connections. If I use
I am trying to send a large json string to a WCF Service created
I'm trying to set up a WCF service hosted in IIS that exposes an
So I'm trying to have an effect that when you click on an image,
I am trying to have a logout page where is displays a messages and
I'm trying to have my Struts2 app redirect to a generated URL. In this
I'm trying to have a new layer appear above existing content on my site
I am trying to have one one layer, and center images within. I.E., if

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.