[RESOLVED] Designing WCF Services
OK so I've got my WCF book now and I've read the first couple of chapters :) So I now know how to create a WCF service, and how to create a client that can use the service contract provided by that service... but what I am not quite sure on (maybe it will be covered later in the book) is how you should design the service contracts that your WCF service provides.
I mean, is it common to just create one endpoint in your WCF service that exposes one class (service contract) and this one class contains every single method/property/function etc that can be called from your service? Or do people normally create several different classes that implement different service contracts?
To help me learn WCF I am going to be making the good old fashioned instant messaging application just for people in my office to be able to use. I want a WCF service to be running on our server that keeps track of who is signed in to the IM app currently and I want it to be responsible for delivering the messages from each client to each recipient. So would I just create one endpoint that exposed a service contract named something like MessengerService and then that one class/contract would contain methods such as "SendMessageToRecipient", "SignIn", "SignOut" etc etc.
Thanks in advance for your wisdom :D
Chris
Re: Designing WCF Services
I've been wondering the same thing, and I came to the conclusion that I will at most ever build 3 services. One for every possible InstanceContextMode; so one that is a singleton and is shared by all users, one that is per session and thus user-specific and one that is stateless. Although from my thoughts so far, the stateless service is not needed if you have another service as well.
Re: Designing WCF Services
The methods should sit in classes which represent what they're about, so it's just common sense. If the methods are all related then it would make sense to have them in a single class and expose that contract, but if they're various aspects of managing the chat, then it won't make sense to have all the methods in a single class. For example,
ChatService.svc.cs
SendMessage()
RetrieveMessage()
GetSmilies()
ChatReporting.svc.cs
GetChatReport()
ChatContacts.svc.cs
GetFriendList()
GetBlockedList()
Re: Designing WCF Services
Ah so it is common to have more than one service contract exposed then, thanks for the clarification :)
Re: [RESOLVED] Designing WCF Services
Yeah, think of them as URLs to web pages... you do want the URLs to make sense. Don't worry about performance hits, as they're stateless calls.