如何控制通用 WCF 返回类型的名称? [英] How can I control the name of generic WCF return types?

查看:17
本文介绍了如何控制通用 WCF 返回类型的名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 WCF Web 服务方法,它的原型是:

I've got a WCF Web Service method whose prototype is:

[OperationContract]
Response<List<Customer>> GetCustomers();

当我将服务引用添加到客户端时,Visual Studio (2005) 创建了一个名为ResponseOfArrayOfCustomerrleXg3IC"的类型,它是Response<List<Customer>>"的包装器.有什么办法可以控制包装名称吗?ResponseOfArrayOfCustomerrleXg3IC 听起来不是很吸引人...

When I add the service reference to a client, Visual Studio (2005) creates a type called "ResponseOfArrayOfCustomerrleXg3IC" that is a wrapper for "Response<List<Customer>>". Is there any way I can control the wrapper name? ResponseOfArrayOfCustomerrleXg3IC doesn't sound very appealing...

推荐答案

您可以在 DataContract 属性中定义自己的名称,如下所示:

You can define your own name in the DataContract attribute like this:

[DataContract(Name = "ResponseOf{0}")]
public class Response<T>

请注意,在您的示例中,{0} 将被替换,您的代理引用类型将为 ResponseOfArrayOfCustomer.

Note that in your example the {0} will be replaced and your proxy reference type will be ResponseOfArrayOfCustomer.

更多信息在这里:WCF:序列化和泛型

这篇关于如何控制通用 WCF 返回类型的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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