问题描述
我有一个WCF Web服务方法,其原型为:
[OperationContract]
Response< List< ;客户和GT;> GetCustomers的();
当我将服务引用添加到客户端时,Visual Studio(2005)创建一个名为ResponseOfArrayOfCustomerrleXg3IC 这是Response< List< Customer >>的包装。有什么办法可以控制包装名称吗? ResponseOfArrayOfCustomerrleXg3IC听起来不太有吸引力...
您可以在 DataContract中定义自己的名称
[DataContract(Name =ResponseOf {0})]
public class Response< T>
请注意,在您的示例中, {0}
将被替换,并且您的代理引用类型将为 ResponseOfArrayOfCustomer
。
更多信息:
I've got a WCF Web Service method whose prototype is:
[OperationContract]
Response<List<Customer>> GetCustomers();
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...
You can define your own name in the DataContract
attribute like this:
[DataContract(Name = "ResponseOf{0}")]
public class Response<T>
Note that in your example the {0}
will be replaced and your proxy reference type will be ResponseOfArrayOfCustomer
.
More info here: WCF: Serialization and Generics
这篇关于我如何控制泛型WCF返回类型的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!