Wcf Service Multithread

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • alsammud
    New Member
    • Dec 2008
    • 1

    Wcf Service Multithread

    Hy,
    I have a Wcf service tat receives files from clients.
    The contract:
    Code:
    #region ServiceContract   
        [ServiceContract]   
        public interface IWcfService   
        {   
            [OperationContract(AsyncPattern = true)]   
            IAsyncResult BeginSendFile(UploadFile file, AsyncCallback callback, object state);   
            FileTransfered EndSendFile(IAsyncResult ar);   
      
        }  
    #endregion ServiceContract
    "UploadFile " and "FileTransfered " are messages.

    and the service

    Code:
    [ServiceBehavior(ConcurrencyMode=ConcurrencyMode.Multiple, InstanceContextMode=InstanceContextMode.PerCall)]   
        public class WcfService : IWcfService
    The service class implements the asynchronous pattern (the BeginSendFile, EndSendFile and the synchronous method, SendFileToServe r, which is called in the Callback method).

    Ex1: If on the client I generate the proxy class with asynchronous operations and call BeginSendFile for each file, the server acts asynchronously (it processes multiple files at a time).
    Ex2: But if I generate the proxy without asynchronous operations, and call SendFile in a thread from ThreadPool (ThreadPool.Que ueUserWorkItem( ...)), one for each file, the server acts synchronously (it processes the files one at a time).

    Why doesn't the server act async on the Ex2 scenario?

    P.S. I followed this tutorial this tutorial. On "Client" section, it is the Ex2 scenario
  • mldisibio
    Recognized Expert New Member
    • Sep 2008
    • 191

    #2
    I have used asynchronous patterns, but not within WCF - that is, I have not used WCF so I am unfamiliar with the contract syntax.

    I am glad you did not post all your code, because that would be unecessary. That said, I don't think you posted enough to indicate the problem.

    When you use ThreadPool.Queu eUserWorkItem, you need to supply the callback. Looking at the tutorial, the callback itself uses a ManualResetEven t to limit itself to processing one item at a time.

    So one idea to look at, without seeing any more of your code, is to follow the signaling path and see if the the callback you are giving to QueueUserWorkIt em is waiting for a signal that the previous task has finished.

    That means not so much that the server is no longer working asynchronously, but rather that your client is limiting the server to only process the next task after the first one has finished.

    I think in example one, you are sending several requests asynchronously. Sending the request is not signaled, so they all go out and the server processes them.

    In example two, my hunch (it may be incorrect) is that the next request is queued but not sent until the first task signals it is finished.

    Comment

    Working...