Wednesday, July 23, 2008

WCF services for LibSecondlife/Second Life®

Ok lets talk a little about the service I'm building. As this is my first time building a WCF service, so I have kept it simple. Looking at it right now the front-end service has 6 methods. All are defined as one way. Still de service is setup as "wsDualHttpBinding", for that there is a second interface, this one doesn't has a front-end page. So a little code: (also a little test on how this looks)

[ServiceContract(CallbackContract = typeof(ISecondService))]
public interface IRegisterService
{
[OperationContract(IsOneWay = true)]
void RegisterClient(Guid clientID);

[OperationContract(IsOneWay = true)]
void LoginUser(Guid clientID, LoginData loginData);

[OperationContract(IsOneWay = true)]
void LogoutUser(Guid clientID);

[OperationContract(IsOneWay = true)]
void RecieveMessage(Guid clientID, RecieveMessageBase recieveMessage);
}


This is the main interface. First you register your client with the service. The two other methods are to login/logout of Second Life. The last method is the method used to send a message from your client to the service (the service receives a message).


Now the nice thing about WCF is that you can have "DualHttpBinding", meaning the service can send message to the client. So when Second Life is sending a message to the client, this is first picked up by the WCF service and then send to the client. First of I was thinking of making a polling application, but this is way cleaner. It has his setbacks but more on that on another post. The interface code for the return message looks like this:


public interface ISecondService
{
[OperationContract(IsOneWay = true)]
void CheckAliveClient();

[OperationContract(IsOneWay = true)]
void SendMessage(SendMessageBase message);
}

The first method is a way to check if the client is still alive. The second is to send a message to the client. Its that simple. :)

Ok more on it soon, now trying to build in Chat.


No comments: