471,107 Members | 1,859 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,107 software developers and data experts.

Wcf Service Multithread

Hy,
I have a Wcf service tat receives files from clients.
The contract:
Expand|Select|Wrap|Line Numbers
  1. #region ServiceContract   
  2.     [ServiceContract]   
  3.     public interface IWcfService   
  4.     {   
  5.         [OperationContract(AsyncPattern = true)]   
  6.         IAsyncResult BeginSendFile(UploadFile file, AsyncCallback callback, object state);   
  7.         FileTransfered EndSendFile(IAsyncResult ar);   
  8.  
  9.     }  
  10. #endregion ServiceContract  
  11.  
"UploadFile" and "FileTransfered" are messages.

and the service

Expand|Select|Wrap|Line Numbers
  1. [ServiceBehavior(ConcurrencyMode=ConcurrencyMode.Multiple, InstanceContextMode=InstanceContextMode.PerCall)]   
  2.     public class WcfService : IWcfService  
  3.  
The service class implements the asynchronous pattern (the BeginSendFile, EndSendFile and the synchronous method, SendFileToServer, 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.QueueUserWorkItem(...)), 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
Dec 8 '08 #1
1 6805
mldisibio
190 Expert 100+
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.QueueUserWorkItem, you need to supply the callback. Looking at the tutorial, the callback itself uses a ManualResetEvent 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 QueueUserWorkItem 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.
Dec 8 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Alice | last post: by
reply views Thread by r_obert | last post: by
2 posts views Thread by zhebincong | last post: by
2 posts views Thread by Joseph | last post: by
6 posts views Thread by jmartin | last post: by
1 post views Thread by mdhaman | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.