Skip to main content
Home Forums Silverlight Programming Programming with .NET - General Call WCF Method in for loop
5 replies. Latest Post by cdey_sl on July 6, 2009.
(0)
cdey_sl
Member
1 points
7 Posts
07-01-2009 7:55 AM |
Hi,
Can any body kelp me to short out the following problem.
I want call WCF method within forloop. But first one after completed the second one call.
private void btnCreate_Click(object sender, RoutedEventArgs e){ string BASE_DIR_PATH = "C:\Test\"; string strFileName = string.Empty; for (int i=0; i < lstFiles.Count; i++) { strFileName = lstFiles[FileCount].Name; JewellWCFClient client = new JewellWCFClient(); client.CreateCompleted += new EventHandler<CreateCropImageCompletedEventArgs>(client_CreateCropImageCompleted); client.CreateAsync(BASE_DIR_PATH, strFileName); }}protected void client_CreateCropImageCompleted(object sender, CreateCropImageCompletedEventArgs e){ if (e.Result) { MessageBox.Show("All File Create..."); }}
i want second Async Method call after first one after completed. Means after call back.
Thanks,
jay nana...
Contributor
3388 points
624 Posts
07-01-2009 8:51 AM |
Try this way.- in your CreateCropImageCompleted method, update one class level variable say Counter when each call completed. and in this method, make async call until your Counter variable does not reach to specific value (in your case it is lstFiles.Count). When all completes, show the message box. Make sure you do all this before this code:
if(e.Result)
{
MessageBox.Show....
}
nirav_20...
274 points
105 Posts
07-02-2009 2:58 AM |
You can use concept of 'out' parameter where you can associate an out parameter with completed event which will identify the call in the loop.
Amanda W...
All-Star
17241 points
1,466 Posts
07-03-2009 6:21 AM |
Hi Chandan,
You can try to refer below code the call the wcf in loop: ServiceReference1.Service1Client client = new autocomp.ServiceReference1.Service1Client(); client.DoWorkCompleted += new EventHandler<autocomp.ServiceReference1.DoWorkCompletedEventArgs>(client_DoWorkCompleted);
for (int i = 0; i < 3; i++) { client.DoWorkAsync(); }
void client_DoWorkCompleted(object sender, autocomp.ServiceReference1.DoWorkCompletedEventArgs e) { // to do.... }
07-06-2009 1:22 AM |
Hi Amanda,
Thanks for your reply.
Its not work for me i want to upload 2 files from WCF service call but after 1 upload completed 2nd file start. With your example the same file upload twice.
Chandan
07-06-2009 1:24 AM |
Hi Jay,
Thanks for your reply. I know this solution. But i want some systemetic solution. Not any bypass solution.
Thanks.