What is service contract?

What operation contract can I put for my WCF service?

  • I am currently developing a C# Windows Form Application that I intend to let it interact with a server. The server will receive posting from a mobile application that I have developed and whenever a posting is received, my Windows Form Application should be notified and give me a notification. And for now I am starting to create a WCF service for it. This is a sample scenario of what I meant, E.g. My mobile application sends an message over to my server. Once my server receives the message, my windows form application should display a new notification showing the content of the message received. so for the operationcontract of the service, what type of methods should i put in in order for me to receive the posting? e.g. [OperationContract] bool receivePosting(int n);

  • Answer:

    I'm not quite clear as to which direction you want to communicate: your "server" needs to notify the Winforms app of a new posting that's been saved? or: your Winforms app asks the "server" about new postings?? I put "server" in quotes because in WCF world, that's a term being used for a specific role. Assuming the first option, you need to do this: your Winforms app needs to be the WCF server - e.g. it needs to define a service contract, operation contract and data contract - and implement those your "posting server" would be the WCF client in this case; whenever a posting is received/stored, then you would call the WCF service in your Winforms app to send a notification (so really, in this setup, your roles are reserved - the Winforms app is the WCF server) As for the operation contract - what does your Winforms app need to know about the new posting? Just the fact a new posting has been received? The whole contents of the posting, or just parts of it?? In any case, you need to define a method on your WCF service that the "posting server" can call and pass all relevant info to the Winforms WCF Server - you don't want to have to make two or more calls just for one notification. So you Service Contract might be: [ServiceContract] public interface IPostingService { [OperationContract] void NotifyAboutPosting(Posting post); } and your Posting class would be the data contract: [DataContract] public class Posting { [DataMember] public int ID { get; set; } [DataMember] public string Description { get; set; } [DataMember] public DateTime PostingTimestamp { get; set; } } Whatever you need to send between those two parties - define it in your data contract which is the argument to your service call

Thomas at Stack Overflow Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.