WCF设计问题C#继承 [英] WCF Design Question C# Inheritance

查看:77
本文介绍了WCF设计问题C#继承的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基本客户端应用程序,用于配置WCF主机并启动第三方应用程序的运行过程,我监控其变化。

我有两个不同的要求[应用程序 - 一个是数据记录器 - 记录器特定数据,另一个是过程的直观表示]

我正在尝试为每个记录器使用基本客户端,ProcessView [每个将与Winform应用程序进行双向通信[多个]实例],我想知道这是一个好的做法,我应该把callbackcontract装饰服务装饰放在哪里,因为每个应用程序的回调是不同的(可以只订阅一些回调而忽略其他等等。



这是一个基本布局,我不确定如何装修服务合同和回调合同。还有一点关于实现。



如果我的Service BehaviourAttribute在接口上将继承,我可以跳过并将该行为放在继承的类上继承或具有不同行为的类上?





 [ServiceContract ?? CallBackContract ??] {IAM UNSURE OF THIS ..] 
IBaseClient
{



}

[ServiceContract? ? CallBackContract ??] {IAM UNSURE OF THIS ..]
BaseClient:IBaseClient
{
.. App for App
..我监控数据并创建事件 for Recorder,ProcessView
}


[ServiceContract,CallBackContract(Recorder)]
IRecorder
{
.. stuff
}

录音机:BaseClient
{
...有不同的回调方法
.. Save();

}


[ServiceContract,CallBackContract(ProcessView)]
IProcessView
{
..这里的东西。
}


ProcessView:BaseClient
{

...有不同的回调方法
..事件PushData() ;




}

WinFormApp
{
.. SaveConfigurationToDB();
.. ViewDB();
.. ReceivePushed();

}

解决方案

您好。



首先, [ServiceContract] 属性应仅应用于方法定义而不应键入。对于类型,您有 [DataContract]

您是否听说过WCF中的KnowTypes?您应该在类型定义中标记您的接口:



KnownType(typeof(BaseClient)或[ServiceKnownType(typeof(BaseClient))]



 [DataContract,KnownType( typeof ( BaseClient))] 
IBaseClient
{
}

[DataContract]
BaseClient:IBaseClient
{
..数据为App
..我监控数据并为记录器创建事件,并且ProcessView
}





以下文章可能对您有所帮助:



http://blogs.msdn.com/b/youssefm/archive/2009/04/21/understanding-known-types.aspx [ ^ ]



http://stackoverflow.com/questions/11272672/data-contract-known-types-and-a-set-of -interfaces-inheriting-each-other [ ^ ]



让我知道它是否适合你。


I have a base client application that configures a WCF host and starts a running process of a third party application which I monitor for changes.
I have two different requirements [Applications - one is a data recorder - recorder particular data, the other is a visual representation of the process]
I am trying to use a base Client for each Recorder, ProcessView [Each will have two way communication to a Winform Application [Multiple Instances], I would like to know if this is a good practice and where I should put the callbackcontract decoration service decoration as Callbacks are different for each application (is is possible to subscribe to only some callbacks and ignore others etc..

Here is a basic layout , I am unsure how to decorate for service contract and callback contracts. and a little on the implementation as well.

If my Service BehaviourAttribute is on the Interface will that be inherited and can I skip that and put the behavior on the class that inherits or have a different behavior on the class that inherits ?


[ServiceContract ?? CallBackContract ??] {IAM UNSURE OF THIS .. ]
IBaseClient
{



}

[ServiceContract ?? CallBackContract ??] {IAM UNSURE OF THIS .. ]
BaseClient : IBaseClient
{
  .. Data For App
 .. I monitor data and create events for Recorder, and ProcessView
}


[ServiceContract , CallBackContract(Recorder)]
IRecorder
{
.. stuff
}

Recorder : BaseClient
{
...Has different callback methods
.. Save();

}


[ServiceContract , CallBackContract(ProcessView)]
IProcessView
{
.. stuff here.
}


ProcessView : BaseClient
{
  
...Has different callback methods
.. Event PushData();




}

WinFormApp
{
.. SaveConfigurationToDB();
.. ViewDB();
.. ReceivePushed();

}

解决方案

Hi.

First of all the [ServiceContract] attribute should only be applied to method definition not to type. For type you have [DataContract]
Have you heard about KnowTypes in WCF? You should mark your interfaces in the type definition:

KnownType(typeof(BaseClient) or [ServiceKnownType(typeof(BaseClient))]

[DataContract, KnownType(typeof(BaseClient))]
IBaseClient
{
}
 
[DataContract]
BaseClient : IBaseClient
{
  .. Data For App
 .. I monitor data and create events for Recorder, and ProcessView
}



Following articles might help you:

http://blogs.msdn.com/b/youssefm/archive/2009/04/21/understanding-known-types.aspx[^]

http://stackoverflow.com/questions/11272672/data-contract-known-types-and-a-set-of-interfaces-inheriting-each-other[^]

Let me know if it worked for you.


这篇关于WCF设计问题C#继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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