应用程序中的webservice方法上的多个异步调用失败,发生异常 [英] Multiple asynchronous calls on webservice method in application fails with exception

查看:279
本文介绍了应用程序中的webservice方法上的多个异步调用失败,发生异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

结果
我想要创建一个连接到互联网的应用程序和使用 Web服务为每一位的是operation.As据我'米而言,我会喜欢用异步方法我使用它已经获得Contacts.I've集合意识到,当我做团体同(意思是让组异步)我遇到的调用错误,但是当使用正常通话有ins't.So我在网上做了一些研究,发现很多人有同样的问题。结果
他们中有些人被要求使用 WCF (对此我不知道插孔).I'll想知道是否有另一种方式来克服这一点。如果不是有人可以点我的可靠资源联机帮我熬过来的?感谢阅读并在这里帮助
是我的代码:

 公共部分类主营:窗
{
// ...
私有静态vmcSession会议;
私人的MyService服务=新的MyService();
私人CONTACTINFO [] loadedcontact;
// ...

公众的main()
{
的InitializeComponent();
//service.addContactCompleted + =新addContactCompletedEventHandler(addContactCompleted);
service.getContactsCompleted + =新getContactsCompletedEventHandler(getContactsCompleted);
service.getGroupsCompleted + =新getGroupsCompletedEventHandler(getGroupsCompleted);
fillContents();
}

私人无效getGroupsCompleted(对象发件人,getGroupsCompletedEventArgs E)
{

{
groupListBox.ItemsSource = e.Result;
}
赶上(异常前)
{
MessageBox.Show(ex.InnerException.Message);
}
}

私人无效getContactsCompleted(对象发件人,getContactsCompletedEventArgs E)
{

{
loadedcontact = E 。结果;
contactListBox.ItemsSource = loadedcontact;
}
赶上(异常前)
{
MessageBox.Show(ex.Message);
}
}

私人无效addContactCompleted(对象发件人,addContactCompletedEventArgs E)
{
抛出新NotImplementedException();
}

公共无效fillContents()
{
displayUserInformation();
loadContacts();
service.getGroupsAsync(session.key,NULL);
//groupListBox.ItemsSource = service.getGroups(session.key,NULL);
cmbSenderIds.ItemsSource = service.getSenderIds(session.key,NULL);
如果(cmbSenderIds.Items.Count大于0)
{
cmbSenderIds.SelectedIndex = 0;
}
loadGrid();


}


公共无效loadContacts()
{
service.getContactsAsync(session.key,NULL);
}



公共无效displayUserInformation()
{
lblName.Content = session.user.firstName;
lblEmail.Content = session.user.email;
lblCreditValue.Content = Decimal.Ceiling(session.user.balance)的ToString();

}


公共无效loadGrid()
{

{
hitoryGrid.ItemsSource =服务.viewMessages(session.key,NULL).ToList();
}
赶上(异常前)
{
MessageBox.Show(ex.Message);
}
}

}


解决方案

解决it.there 2种方法与异步调用,一个具有通话的附加参数唯一ID.each需要的ID,所以我通过新的GUID给它,这就是it.thanks的尝试帮助我



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 = loadedcontact;
        }
        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

这篇关于应用程序中的webservice方法上的多个异步调用失败,发生异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆