WCF Call client methods asyncronously RRS feed

  • Question

  •     public interface IService
            [OperationContract(AsyncPattern = true, IsInitiating = false)]
            IAsyncResult Beginsomeservicemethod(string msg, AsyncCallback callback, object state);
            bool Endsomeservicemethod(IAsyncResult result);
    public interface IClientCallback
            int clientmethod1(string e);
            [OperationContract(IsOneWay = true)]
            void clientmethod2(string name);

    This is how my interfaces look like .   The service methods are implemented asyncronously , no problem there.  

    The issue is that clientmethod1 takes time to be executed and I want the service to be able to call   clientmethod2 meanwhile . 


    I noticed that asyncpattern = true doesn't work for client operation contracts and the server crashes with an exception at startup . So how do I do this ? 

    Friday, January 13, 2012 9:34 AM


  • Hi,

    You can write Asyn Model in the Service where you want to call the clientmethod1 as below.


    EventHandler myHandler = delegate(object s, EventArgs args)
                    //Call your Client Method 1
                IAsyncResult myResult = myHandler.BeginInvoke(null, null, null, null);
                //Call your Client Method 2


    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful". Sudhakar
    • Marked as answer by Yi-Lun Luo Thursday, January 19, 2012 9:27 AM
    Friday, January 13, 2012 11:45 AM