问题描述
我遇到了一些困难与WCF RIA服务类似于this螺纹。
I'm experiencing some difficulties with a WCF RIA Services similar to the problem specified in this thread.
该DomainService的方法,我创建(查询方法)应该采取一个复杂的对象参数。例如DomainService的方式:
The domainservice method I'm creating (a Query method) should take a complex object parameter.example domainservice method:
public ComplexObjectResult GetComplexObject(ComplexObjectParameter test)
{
//do stuff
}
参数对象:
public class ComplexObjectParameter
{
[Key]
public decimal ID { get; set; }
... other fields
}
我得到这个编译错误:域操作项GetComplexObject中的错误70参数测试必须是$ P $之一pdefined序列化类型
在一些搜索网站上,我发现这个MSDN线程。它指出,这是RIA服务的限制和线程指定没有像样的解决方法。
After some searching on the web I found this msdn thread. It states that this is a limitation of RIA services and the thread specifies no decent workarounds.
现在似乎有一些脏的解决方法:
Now there seem to be some dirty workarounds:
-
改变复杂的参数输入字符串和序列化/反序列化parameterobject我们自己,我觉得非常哈克的解决方案。
Change the complex parameter to type string and Serialize/Deserialize the parameterobject ourself which I find a very hacky solution.
使用[调用]关于域名服务方法和宽松的所有RIA跟踪功能,为此,我在第一时间利用RIA标签。
Use [Invoke] tag on the domain service method and loose all RIA tracking functionality, for which I am using RIA in the first place.
是否有提到的解决方案,拥有更低的缺点的替代品?有一个人发现了一个更优雅的解决这一问题?
Are there alternatives for the mentioned solutions that have less disadvantages? Has someone found a more elegant workaround for this problem?
感谢
推荐答案
肮脏的解决方法三,是使用[调用]属性和方法添加到域服务来公开的复杂类型,它通知WCF RIA工具来在客户端创建实体:
Dirty workaround three, is to use the [Invoke] attribute and add a method to the domain service to expose the "complex type", which informs the WCF RIA tooling to create the entity on the client-side:
public ComplexObjectParameter ExposeComplexObjectParameter()
{
throw new NotSupportedException();
}
我把NotSupportedException异常在我的域名服务方法,以prevent无声的故障,如果该方法是不断远程调用。
I put NotSupportedException in my domain service methods to prevent silent failures if the method is ever called remotely.
我不知道该解决方案如何影响输的所有RIA追踪功能的问题。它没有回答如何使用复杂类型作为参数来创建一个可组合查询。
I'm not sure about how this solution affects the issue of losing "all RIA tracking functionality". It does not answer how to create a composable query using a complex type as a parameter.
这是肮脏的,但抽象的问题最接近问题的根源。主叫和接收code是清洁的。这保持了优雅在较高的水平,同时推动脏了。
It's dirty, but abstracts the problem closest to the source of problem. The calling and receiving code is cleaner. This maintains the "elegance" at the higher level while pushing the dirty down.
这篇关于RIA服务传递复杂的对象作为参数传递给查询域名服务方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!