Skip to main content

Microsoft Silverlight

Call WCF Method in for loopRSS Feed

(0)

cdey_sl
cdey_sl

Member

Member

1 points

7 Posts

Call WCF Method in for loop

 

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,

Chandan

jay nanavati
jay nana...

Contributor

Contributor

3388 points

624 Posts

Re: Call WCF Method in for loop

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....

}

 

Jay K Nanavaty
www.technologyopinion.com
Mark as answer if it helps. It will also help others...

nirav_2052003
nirav_20...

Member

Member

274 points

105 Posts

Re: Call WCF Method in for loop

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 Wang - MSFT
Amanda W...

All-Star

All-Star

17241 points

1,466 Posts

Re: Call WCF Method in for loop

 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....
        }

Amanda Wang
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.

cdey_sl
cdey_sl

Member

Member

1 points

7 Posts

Re: Re: Call WCF Method in for loop

 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.

Thanks,

Chandan

cdey_sl
cdey_sl

Member

Member

1 points

7 Posts

Re: Re: Call WCF Method in for loop

 Hi Jay,

Thanks for your reply. I know this solution. But i want some systemetic solution. Not any bypass solution.

Thanks.

Chandan

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities