Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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 ?


C#
[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();

}
Posted
Updated 10-Jul-15 8:29am
v2

1 solution

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))]

C#
[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.
 
Share this answer
 
Comments
stixoffire 13-Jul-15 0:42am    
1st thank you for your answer it is much appreciated. In reading over the article on stack that you have linked to it is really hard for me to follow , I am as you can guess learning WCF and there is a lo to learn, I am also working with 2 other libraries I am trying to learn and make work with WCF being the glue between two applications one is a service and the other Winforms application.
So [ServiceContract] only on the interface not on the class and The behavior attribute will be on the class.
I had heard of the KnownType attribute but thought that was for cross platform communications and not really needed in Windows .NET to Windows .NET applications.
stixoffire 13-Jul-15 0:48am    
In the second article blogs understanding Known Types, this is the conclusion of the article:
After all this talk about known types, you may be surprised to learn that you should try to avoid using known types.
[no name] 13-Jul-15 7:34am    
sorry, but I've never had a need in my practice to use ServiceCallbacks for real time two way message exchange. What I can suggest for you is to find on the web a simplest possible tutorial for two way instant message exchange, for example console application, setup and run it locally, try to understand how it supposed to work. Let's say that following tutorial is really easy to run and understand:

http://stackoverflow.com/questions/1044174/what-steps-do-i-need-to-take-to-use-wcf-callbacks

you can create a simple ConsoleApplication, run it and using breakpoints debug it line by line to see what happens. In this tutorial, you have IMyContractCallback which defines contract for CallBack - action executed on the client side after server ervice completed his work. IMyContract - operation contract for the service. MyService - service, where you put your service logic.

MyContractClient - client wrapper for calling the service. MyCallbackClient - here you define code which is executed on the client side after service completed it's job.

NOTE, that IMyContractCallback and IMyContract have be shared between server and client, so you can create a Class Library project and reference it from both sides - service and client.

Hope this helps.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900