Remoting Client-Side

After everything was done on the server-side of the Remoting implementation, inside the Windows Service, it was time to add the consumer side. In the case of this project, the consumer was an ASP.NET Webservice running on the same machine.

This required little effort. First, System.Runtime.Remoting had to be referenced, together with the assembly containing the interface used for the controller object. After this it was possible retrieve the controller object with the following code:

[csharp] private IPlayerServiceController GetPlayerServiceController() { return (IPlayerServiceController)Activator.GetObject( typeof(IPlayerServiceController), String.Format("tcp://{0}:{1}/MediaServicePlayerController", this.configData.RemotingHost, this.configData.RemotingPort)); } / GetPlayerServiceController / [/csharp]

In this solution, the webservice does not need to reference the assembly containing the real controller, but only an assembly that contains the interface. The real implementation is running on the server-side, as an instantiated, marshalled object.

When the instance got returned, it was possible to use it very simple, like this code:

[csharp] [WebMethod(Description="Stop playing the queue.")] public void Stop() { this.GetPlayerServiceController().StopPlaying(); } / Stop / [/csharp]