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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:19:03+00:00 2026-05-27T03:19:03+00:00

I have to communicate 2 WPF application. To communicate, i am using a WCF

  • 0

I have to communicate 2 WPF application.
To communicate, i am using a WCF windows service running on local machine.

When one of then calls a method on service, service calls back to other one. There is just one callback interface and all methods are written in it. But, 2 WPF apps are not using same callback methods. So, i am forced to implement unused methods.

So, I am tried to find if i can set 2 different and independent callback interfaces on service, but i couldn’t. Is there any way to do it?

UPDATE

My sample code:

IDeviceCallBack

public interface ITestCallBack1
{
    [OperationContract(IsOneWay = true)]
    void Test1();
}

public interface ITestCallBack2
{
    [OperationContract(IsOneWay = true)]
    void Test2();
}

public interface IDeviceCallback : ITestCallBack1, ITestCallBack2
{ }

IDevice

[ServiceContract(CallbackContract = typeof(ITestCallBack1))]
public interface ITestContract1
{ }

[ServiceContract(CallbackContract = typeof(ITestCallBack2))]
public interface ITestContract2
{ }


[ServiceContract(CallbackContract = typeof(IDeviceCallback))]
public interface IDevice : ITestContract1, ITestContract2
{
    [OperationContract]
    bool Subscribe();

    [OperationContract]
    bool Unsubscribe();
}

What I want:
WPF1

[CallbackBehaviorAttribute(ConcurrencyMode = ConcurrencyMode.Multiple)]
public partial class MainWindow : Window, ITestCallBack1, IDisposable//,IDeviceCallBack
{
    private InstanceContext context;
    private DeviceClient deviceClient;

    public MainWindow()
    {
        InitializeComponent();
        context = new InstanceContext(this);
        deviceClient = new DeviceServiceReference.DeviceClient(context);
    }

    public void Dispose()
    {
        deviceClient.Close();
    }

    public void Test1()
    {
        throw new NotImplementedException();
    }

    // Not Wanted
    //public void Test2()
    //{
    //    throw new NotImplementedException();
    //}
}

WPF2

[CallbackBehaviorAttribute(ConcurrencyMode = ConcurrencyMode.Multiple)]
public partial class MainWindow : Window, ITestCallBack2, IDisposable //,IDeviceCallBack
{
    private InstanceContext context;
    private DeviceClient deviceClient;

    public MainWindow()
    {
        InitializeComponent();
        context = new InstanceContext(this);
        deviceClient = new DeviceServiceReference.DeviceClient(context);
    }

    public void Dispose()
    {
        deviceClient.Close();
    }

    // Not Wanted
    //public void Test1()
    //{
    //    throw new NotImplementedException();
    //}

    public void Test2()
    {
        throw new NotImplementedException();
    }
}
  • 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-27T03:19:03+00:00Added an answer on May 27, 2026 at 3:19 am

    I am not completely clear on your requirement here but I will take a shot at helping anyway…

    So, you can have only a single callback interface per service in WCF which means you will need two services. You can do some inheritance though so that you do not have to duplicate anything on your server. Following is an example that I hope explains how to do it…

    // A base interface for both services that contains the common methods
    [ServiceContract]
    public interface ITestService
    {
        [OperationContract]
        bool Subscribe();
    
        [OperationContract]
        bool Unsubscribe();
    }
    
    // Service interface for service 1, using callback 1
    [ServiceContract(CallbackContract = typeof(ITestCallBack1))]
    public interface ITestContract1 : ITestService
    {
    }
    
    // Callback interface for service 1
    public interface ITestCallBack1
    {
        [OperationContract(IsOneWay = true)]
        void Test1();
    }
    
    // Service interface for service 2, using callback 2
    [ServiceContract(CallbackContract = typeof(ITestCallBack2))]
    public interface ITestContract2 : ITestService
    {
    }
    
    // Callback interface for service 2
    public interface ITestCallBack2
    {
        [OperationContract(IsOneWay = true)]
        void Test2();
    }
    
    // This is a base class that contains everything common to the two services
    public abstract class TestServiceBase<T> : ITestService
    {
    
        public bool Subscribe()
        {
            // Let's say that after subscribing we will wait for a bit
            // and call back (just an example)
            ThreadPool.QueueUserWorkItem(o =>
                                             {
                                                 Thread.Sleep(5000);
                                                 RaiseCallback((T) o);
                                             },
                                         OperationContext
                                             .Current
                                             .GetCallbackChannel<T>());
            return true;
        }
    
        public bool Unsubscribe()
        {
            // Do whatever you need here
            return true;
        }
    
        // abstract method to raise the callback because the method names
        // are different for the two callback interfaces - notice the overriding
        // method does not need to do anything except call the correctly named method
        protected abstract void RaiseCallback(T callback);
    }
    
    // Concrete implementation of TestService1 - you can see that it
    // only does whatever is specific for it
    public class TestService1 : TestServiceBase<ITestCallBack1>, ITestContract1
    {
        // Notice I get the callback1 interface to call the client
        protected override void RaiseCallback(ITestCallBack1 callback)
        {
            callback.Test1();
        }
    }
    
    // Concrete implementation of TestService2 - you can see that it
    // only does whatever is specific for it
    public class TestService2 : TestServiceBase<ITestCallBack2>, ITestContract2
    {
        // Notice I get the callback2 interface to call the client
        protected override void RaiseCallback(ITestCallBack2 callback)
        {
           callback.Test2();
        }
    }   
    

    Here is the configuration for the services:

    <system.serviceModel>
      <services>
        <service name="Demo.TestService1" behaviorConfiguration="NetTcpServiceBehavior">
          <host>
            <baseAddresses>
              <add baseAddress="net.tcp://localhost:9999/TestService1"/>
            </baseAddresses>
          </host>
         <endpoint address="" binding="netTcpBinding" contract="Demo.ITestContract1" bindingConfiguration="NetTcpBindingConfiguration"/>
         <endpoint address="mex" binding="netTcpBinding" contract="IMetadataExchange" bindingConfiguration="MexBindingConfiguration"/>
        </service>
        <service name="Demo.TestService2" behaviorConfiguration="NetTcpServiceBehavior">
          <host>
            <baseAddresses>
              <add baseAddress="net.tcp://localhost:9999/TestService2"/>
            </baseAddresses>
          </host>
          <endpoint address="" binding="netTcpBinding" contract="Demo.ITestContract2" bindingConfiguration="NetTcpBindingConfiguration"/>
          <endpoint address="mex" binding="netTcpBinding" contract="IMetadataExchange" bindingConfiguration="MexBindingConfiguration"/>
        </service>
      </services>
      <bindings>
        <netTcpBinding>
          <binding name="NetTcpBindingConfiguration"
                   maxConnections="5"
                   portSharingEnabled="true">
            <security mode="None">
              <transport protectionLevel="None"/>      
            </security>
          </binding>
          <binding name="MexBindingConfiguration" portSharingEnabled="true">
            <security mode="None">
              <transport protectionLevel="None"/>    
            </security>
          </binding>
        </netTcpBinding>
      </bindings>
      <behaviors>
        <serviceBehaviors>
          <behavior name="NetTcpServiceBehavior">
            <serviceMetadata />
          </behavior>
        </serviceBehaviors>
      </behaviors>
    </system.serviceModel>
    

    Then on the client you need a reference to the service that you are interested in the callback for (so your WPF 1 would reference /TestService1 and WPF 2 /TestService2).

    Notice that you can put all the logic that is common to your two services in the TestServiceBase class – it takes the callback interface just so that it can call it. In reality you may not need this – I do not know under what circumstances you are wishing to call back to the client

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently developing a application where I will have multiple windows open using C#
I've a small question I've a WPF application, and one method takes some times(it
I have made an Excel VSTO Application(WPF) which call a WCF working with IIS
I have a wpf app that needs to communicate(exchange data) with a custom designed
I have some forms that communicate with server using AJAX for real reasons: cascade
I have two applications written in Java that communicate with each other using XML
I have an application that uses rest to communicate to a server, i would
I have a WPF application which so far has been client only, but now
I've been reading about using ExternalInterface to have Flash communicate with JavaScript. I need
I have a substanital WPF application set up as follows: Views, ViewModels, Business Objects

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.