开发者

Multiple asynchronous calls on webservice method in application fails with exception

开发者 https://www.devze.com 2022-12-30 15:53 出处:网络
i\'m trying to create an application which connects to internet and consume web services for every of it\'s operation.As far as i\'m concerned i\'ll like to useasync method which i\'m using already to

i'm trying to create an application which connects to internet and consume web services for every of it's operation.As far as i'm concerned i'll like to useasync method which i'm using already to get a collection of Contacts.I've realized that when i'm doing the same for groups (meaning getting groups async) i'm having errors in the calls , but when using normal call there ins't.So i did some research online and find that a lot of people has the same problem.

Some of them are asked to use WCF (for which i don't know jack).I'll like to know if there is another way to overcome this. if not can somebody point me to reliable resource online and help me get through it? thanks for reading and helping here is my code:

 public partial class main : Window
{
    //...
    private static vmcSession session;
    private MyService service = new MyService();
    private contactInfo[] loadedcontact;
    //....

    public main()
    {
        InitializeComponent();
        //service.addContactCompleted +=new addContactCompletedEventHandler(addContactCompleted);
        service.getContactsCompleted += new getContactsCompletedEventHandler(getContactsCompleted);
        service.getGroupsCompleted += new getGroupsCompletedEventHandler(getGroupsCompleted);
        fillContents();
    }

    private void getGroupsCompleted(object sender, getGroupsCompletedEventArgs e)
    {
        try
        {
            groupListBox.ItemsSource = e.Result;
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.InnerException.Message);
        }
    }

    private void getContactsCompleted(object sender, getContactsCompletedEventArgs e)
    {
        try
        {
            loadedcontact = e.Result;
            contactListBox.ItemsSource = loadedconta开发者_运维问答ct;
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }

    private void addContactCompleted(object sender, addContactCompletedEventArgs e)
    {
        throw new NotImplementedException();
    }

    public void fillContents()
    {
        displayUserInformation();
        loadContacts();
        service.getGroupsAsync(session.key, null);
        //groupListBox.ItemsSource = service.getGroups(session.key, null);
        cmbSenderIds.ItemsSource = service.getSenderIds(session.key, null);
        if (cmbSenderIds.Items.Count > 0)
        {
            cmbSenderIds.SelectedIndex = 0;
        }
        loadGrid();


    }


    public void loadContacts()
    {
        service.getContactsAsync(session.key, null);
    }



    public void displayUserInformation()
    {
        lblName.Content = session.user.firstName;
        lblEmail.Content = session.user.email;
        lblCreditValue.Content = Decimal.Ceiling(session.user.balance).ToString();

    }


    public void loadGrid()
    {
        try
        {
            hitoryGrid.ItemsSource = service.viewMessages(session.key, null).ToList();
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }     

}


solve it.there are 2 methods with async calls, one with additional parameter Unique ID.each of the call needed ID, so i pass new GUID to it and that's it.thanks for trying helping me

0

精彩评论

暂无评论...
验证码 换一张
取 消