简体   繁体   English

WCF代理类

[英]WCF Proxy Class

I have in a project am working on, a couple Model Classes where most of them inherit from one base class, The base class is marked with the attribute with Sub Classes Types. 我在一个项目中正在研究几个模型类,其中大多数模型类都继承自一个基类。该基类带有带有Sub Classes Types的属性标记。

In my Service, the function returns an Object of the base class, the implementation of the function will of course return one of the sub Classes. 在我的Service中,该函数返回基类的Object,该函数的实现当然将返回子类之一。

When i use Visual Studio for Creating the proxy Classes it will only create the Base Class in the proxy without any of the sub classes since there is no method in the Service that will return an Instance of the sub class directly. 当我使用Visual Studio创建代理类时,它将仅在代理中创建基类,而没有任何子类,因为Service中没有方法可以直接返回子类的实例。

my question Is there a way to force the proxy Generator to generate the classes for Sub Classes even if they aren't used directly in the service? 我的问题有没有办法强迫代理生成器为子类生成类,即使它们未在服务中直接使用?

Use the ServiceKnownTypeAttribute: 使用ServiceKnownTypeAttribute:

[DataContract]
[KnownType(typeof(ResponseType1))]
[KnownType(typeof(ResponseType2))]
public class BaseResponseType
{
    ...
}

[DataContract]
public class ResponseType1: BaseResponseType
{
    ...
}

[DataContract]
public class ResponseType2: BaseResponseType
{
    ...
} 

Then your service operation: 然后您的服务操作:

[OperationContract]
BaseResponseType ProcessSomething (Something thing);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM