我可以强制svcutil.exe的生成WCF服务的数据合同? [英] Can I force svcutil.exe to generate data contracts for a WCF service?
本文介绍了我可以强制svcutil.exe的生成WCF服务的数据合同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想迫使 SvcUtil工具
来生成的所有数据在装配合同所使用的WCF,不管类型是否引用由给定操作合同
[DataContract]
公共类Foo {}
[DataContract]
公共类酒吧:富{}
[的ServiceContract]
公共接口IService
{
[OperationContract的]
无效获取(富富);
}
鉴于此设置我不能让 SvcUtil工具
,因为没有当前引用它操作合同生成一个版本酒吧
的。有没有办法强制 SvcUtil工具
生成酒吧
?
中的数据合约< DIV CLASS =h2_lin>解决方案
一KnownType属性添加到Foo类
[KnownType (typeof运算(酒吧))]
[DataContract]
公共类Foo {}
I would like to force svcutil
to generate all data contracts in an assembly that is used by WCF, regardless of whether or not a type is referenced by a given operation contract.
[DataContract]
public class Foo { }
[DataContract]
public class Bar : Foo { }
[ServiceContract]
public interface IService
{
[OperationContract]
void Get(Foo foo);
}
Given this setup I cannot get svcutil
to generate a version of Bar
as there are no operation contracts that currently reference it. Is there a way to force svcutil
to generate the data contract for Bar
?
解决方案
Add a KnownType attribute to the Foo class
[KnownType(typeof(Bar))]
[DataContract]
public class Foo { }
这篇关于我可以强制svcutil.exe的生成WCF服务的数据合同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文