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 7070503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:34:28+00:00 2026-05-28T05:34:28+00:00

I have a non-serializable object that I would like to access from a separate

  • 0

I have a non-serializable object that I would like to access from a separate process. I’ve looked around and it seems the only viable option is to use WCF but I’m not sure how to do this as I’m new to WCF. If I create a WCF service, how do I ‘hook’ the WinForm into the various events in the WCF service? For example, the user communicates with the WCF service directly and I would likemy WinForm client to be notified. How would I be able to know when the user has done something with the WCF service and have the WinForm client pick up on that?

  • 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-28T05:34:28+00:00Added an answer on May 28, 2026 at 5:34 am

    A way to achieve what you are looking for is to implement a callback contract on your service. Then your win-forms app would be able to “subscribe” to events fired on the service (such as modifications to your object).

    To do this you implement a service contract with a callback contract:

    [ServiceContract]
    public interface IMyService_Callback
    {
        [OperationContract(IsOneWay = true)]
        void NotifyClients(string message);
    }
    
    [ServiceContract(CallbackContract = typeof(IMyService_Callback))]
    public interface IMyService
    {
        [OperationContract]
        bool Subscribe();
    }
    

    You then implement your service:

    [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Reentrant)]
    public class MyService : IMyService
    {
        private List<IMyService_Callback> callbacks;
    
        public MyService()
        {
            this.callbacks = new List<IMyService_Callback>();
        }
    
        private void CallClients(string message)
        {
            callbacks.ForEach(callback => callback.NotifyClients(message));
        }
    
        public bool Subscribe()
        {
            var callback = OperationContext.Current.GetCallbackChannel<IMyService_Callback>();
    
            if (!this.callbacks.Contains(callback))
            {
                this.callbacks.Add(callback);
            }
    
            // send a message back to the client
            CallClients("Added a new callback");
    
            return true;
        }
    }
    

    In your winforms client you only need to implement the callback method:

    [CallbackBehavior(ConcurrencyMode = ConcurrencyMode.Reentrant, UseSynchronizationContext = false)]
    public partial class ServiceClient : Form, IMyService_Callback
    {
        // Sync context for enabling callbacks
        SynchronizationContext uiSyncContext;
    
        public ServiceClient()
        {
            InitializeComponent(); //etc.
    
            uiSyncContext = SynchronizationContext.Current;
    
            // Create proxy and subscribe to receive callbacks
            var factory = new DuplexChannelFactory<IMyService>(typeof(ServiceClient), "NetTcpBinding_IMyService");
            var proxy = factory.CreateChannel(new InstanceContext(this));
            proxy.Subscribe();
        }
    
        // Implement callback method
        public void NotifyClients(string message)
        {
            // Tell form thread to update the message text field
            SendOrPostCallback callback = state => this.Log(message);
    
            uiSyncContext.Post(callback, "Callback");
        }
    
        // Just updates a form text field
        public void Log(string message)
        {
            this.txtLog.Text += Environment.NewLine + message;
        }
    }    
    

    Config for service:

    <system.serviceModel>
      <services>
        <service name="TestService.MyService" behaviorConfiguration="Normal">
          <endpoint 
            address="net.tcp://localhost:8000/MyService" 
            contract="TestService.IMyService" 
            binding="netTcpBinding" />
        </service>
      </services>
      <behaviors>
        <serviceBehaviors>
          <behavior name="Normal" >
            <serviceDebug includeExceptionDetailInFaults="true"/>
          </behavior>
        </serviceBehaviors>
      </behaviors>
    </system.serviceModel>
    

    Config for client

    <system.serviceModel>
      <client>
        <endpoint address="net.tcp://localhost:8000/MyService" 
                  binding="netTcpBinding"
                  contract="TestService.IMyService"
                  name="NetTcpBinding_IMyService">
        </endpoint>
      </client>
    </system.serviceModel>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to detect strings that have non-whitespace characters in them. Right now
I'd like to open a pipe using popen() and have non-blocking 'read' access to
I've been trying to deal with some delimited text files that have non standard
I have a non-.Net executable file that is included in my .net assembly as
We have a (non-web app) Spring application that throws a NoSuchBeanDefinitionException when running tests
I have an (non-virtualized) ItemsControl that binds its ItemsSource to a ObeservableCollection of ViewModel
Is it possible to have final transient fields that are set to any non-default
Is there a way to have non-standard attributes like onselectstart oncontextmenu ... in a
I have an object not written by myself that I need to clone in
Auto generating entities from a legacy database. Many of the tables have non standard

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.