Can I force svcutil.exe to generate data contracts for a WCF service?

北慕城南 提交于 2020-01-01 10:07:57

问题


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?


回答1:


Add a KnownType attribute to the Foo class

[KnownType(typeof(Bar))]
[DataContract]
public class Foo { }


来源:https://stackoverflow.com/questions/496922/can-i-force-svcutil-exe-to-generate-data-contracts-for-a-wcf-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!