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

  • Home
  • SEARCH
  • 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 7868199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:55:35+00:00 2026-06-03T00:55:35+00:00

I have a duplex WCF service. In the service contract, I have 3 async

  • 0

I have a duplex WCF service. In the service contract, I have 3 async methods and 1 normal method (close session). In tha callback contract I only have 1 void method that is not async.

When I generate the proxy with svcUtil I use the /a paramter, and get the .cs. If I open the this file, I can see that is generated the Begin/end method for the no async method of the contract, I don’t know well why, because this methods is not marked as async in the contract. Anyway, this is no the problem.

The problem is with the method of the callback contract. In my client application, I implement the callback interface, but I have implemented one method, an sync method, so I have not the Begin/End methods. However, I can’t compile because I have an error, that the class that implement the callback interface does not implement the Begin/end methods.

Which is the problem?

Thanks.
Daimroc.

  • 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-06-03T00:55:36+00:00Added an answer on June 3, 2026 at 12:55 am

    The class which implements the callback interface needs to implement the asynchronous methods as well (since they’re defined in the interface), but if an interface has both synchronous and synchronous versions of the same method, the synchronous one is invoked by default. In the code below, the asynchronous operations in the callback class just throw, but the code works just fine.

    public class StackOverflow_10362783
    {
        [ServiceContract(CallbackContract = typeof(ICallback))]
        public interface ITest
        {
            [OperationContract]
            string Hello(string text);
        }
        [ServiceContract]
        public interface ICallback
        {
            [OperationContract(IsOneWay = true)]
            void OnHello(string text);
    
            [OperationContract(IsOneWay = true, AsyncPattern = true)]
            IAsyncResult BeginOnHello(string text, AsyncCallback callback, object state);
            void EndOnHello(IAsyncResult asyncResult);
        }
        public class Service : ITest
        {
            public string Hello(string text)
            {
                ICallback callback = OperationContext.Current.GetCallbackChannel<ICallback>();
                ThreadPool.QueueUserWorkItem(delegate
                {
                    callback.OnHello(text);
                });
    
                return text;
            }
        }
        class MyCallback : ICallback
        {
            AutoResetEvent evt;
            public MyCallback(AutoResetEvent evt)
            {
                this.evt = evt;
            }
    
            public void OnHello(string text)
            {
                Console.WriteLine("[callback] OnHello({0})", text);
                evt.Set();
            }
    
            public IAsyncResult BeginOnHello(string text, AsyncCallback callback, object state)
            {
                throw new NotImplementedException();
            }
    
            public void EndOnHello(IAsyncResult asyncResult)
            {
                throw new NotImplementedException();
            }
        }
        public static void Test()
        {
            string baseAddress = "net.tcp://" + Environment.MachineName + ":8000/Service";
            ServiceHost host = new ServiceHost(typeof(Service), new Uri(baseAddress));
            host.AddServiceEndpoint(typeof(ITest), new NetTcpBinding(SecurityMode.None), "");
            host.Open();
            Console.WriteLine("Host opened");
    
            AutoResetEvent evt = new AutoResetEvent(false);
            MyCallback callback = new MyCallback(evt);
            DuplexChannelFactory<ITest> factory = new DuplexChannelFactory<ITest>(
                new InstanceContext(callback),
                new NetTcpBinding(SecurityMode.None),
                new EndpointAddress(baseAddress));
            ITest proxy = factory.CreateChannel();
    
            Console.WriteLine(proxy.Hello("foo bar"));
            evt.WaitOne();
    
            ((IClientChannel)proxy).Close();
            factory.Close();
    
            Console.Write("Press ENTER to close the host");
            Console.ReadLine();
            host.Close();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a WCF Service with a CallBack Contract (duplex), and when I
I have a WCF service on a duplex channel, with a callback contract. The
I have a WCF duplex service with a 2 way method called GetList, plus
I have a duplex Wcf service and I'd like to get a reference to
Well, in my first version of my service, I have a duplex contract, so
I've written a WCF service with a duplex contract which asynchronously calls back the
Hi have quite a problem with an Service running WCF in duplex-mode. It leaks
I have hosted a WCF duplex service ( netTcpBinding ) in a Windows Service
i have a wcf service (nettcpbinding, duplex) wich works very well. today i hit
I have a working duplex WCF service with WSDualHttpBinding . My problem is figuring

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.