我*必须*在 Silverlight WCF 客户端中使用 ObservableCollection 吗? [英] Do i *have* to use ObservableCollection in Silverlight WCF client?

查看:22
本文介绍了我*必须*在 Silverlight WCF 客户端中使用 ObservableCollection 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 WCF 中访问 Silverlight 时,您会使用 ObservableCollection

When accessing Silverlight in WCF you get proxies generated with ObservableCollection

当你进行数据绑定时很好,但当你只是调用一个方法时有点笨拙.例如以下服务方法:

Thats fine when you're databinding, but a little clumsy when you're just calling a method. For instance the following service method :

    [OperationContract]
    public SearchOrdersMsgOut SearchOrders(ShippingStatusType[] shippingStatuses,
                                           string[] orderId)
    {
    }

使用 ObservableCollection 生成.什么!它们只是参数.我为什么要观察"它们?

gets generated with ObservableCollection. What! They're just parameters. Why would I ever want to 'observe' them?

如果我必须这样做,我很好 - 但是当我知道我从不进行数据绑定时,似乎应该有一种方法可以强制使用简单的数组结构 - 特别是在输入消息上.

I'm fine if I have to do this - but it seems like there should be a way to force simple array structures when I know I'm never databinding - especially on input messages.

我更愿意这样做:

 searchCriteria.PaymentStatus = new [] { PaymentStatusType.PaymentFailed, PaymentStatusType.Unpaid };               

比这个:

 searchCriteria.PaymentStatus = new ObservableCollection<PaymentStatusType> { PaymentStatusType.PaymentFailed, PaymentStatusType.Unpaid };

有办法吗?

附注.我确实使用 SearchCriteria 对象作为我的搜索条件 - 但我简化了这个例子,想知道参数的处理方式是否不同.

PS. I do actually use a SearchCriteria object for my search criteria - but I simplified for this example wondering if parameters were handled differently.

推荐答案

您可以在整个服务范围内执行此操作,但不能在每个方法的基础上执行此操作.在添加服务引用"对话框中,单击高级",然后选择System.Array"作为集合类型.但我不知道有什么方法可以逐个方法地执行此操作,即对某些方法使用数组,对其他方法使用 ObservableCollection.

You can do this service-wide, but not on a per-method basis. In the Add Service Reference dialog box, click on "Advanced", and choose "System.Array" for the Collection type. But I'm not aware of any way to do it method-by-method, i.e., use array for some methods and ObservableCollection for others.

这篇关于我*必须*在 Silverlight WCF 客户端中使用 ObservableCollection 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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