Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

How to Build Custom Sink Providers for .NET Remoting : Page 2

If the default remoting behavior doesn't suit your needs, change it! Leverage .NET Remoting and its extensible infrastructure to build customized message sinks that can help integrate your applications.


advertisement
Constructing a Remoting Application
You can implement three different interfaces for message sinks: IMessageSink, IClientChannelSink, and IServerChannelSink. The difference between these interfaces is that the IMessageSink interface can access and change the original dictionary object regardless of the serialization format, whereas the other two interfaces have access to the serialized message represented as stream objects only. Another difference is that the IClientChannelSink makes a distinction between synchronous and asynchronous calls during the request processing phase; but IServerChannelSink does not make that distinction. The sample project demonstrates how to implement a data serialization sink derived from IClientChannelSink.

To implement the ClientSinkSerializer, first create a simple remoting server with a single method exposed. Here's an example.

public interface IRemotingExample { string GetHelloWorld(); } public class RSExample : MarshalByRefObject, IRemotingExample { public string GetHelloWorld() { return "Hello World"; } }

The RSExample class has a single GetHelloWorld method, which returns the string "Hello World". The sample code defines the IRemotingExample interface in a separate assembly so it can be shared by the client and the server. I'll use IIS to host the remoting server application. To configure the application, create a virtual directory with a bin subdirectory, and copy the assemblies containing the remoting server class and the interface to that bin directory. Then create a Web.config file, as shown in Listing 1, and place it in the virtual directory. The configuration file lets you specify the type, assembly name, and URI for the remoting server.

Next you'll construct a client application to consume the remoting server. The sample uses a Windows forms application with one form containing a Button and a Label control. Add the event-handler code shown in Listing 2 to handle the button's Click event. Finally, add the following line of code to the form's constructor:

RemotingConfiguration.Configure(filepath);

Calling the Configure method and passing a string parameter specifying the location of the client application's configuration file lets you specify important details for the remoting infrastructure, such as the URI for the remoting endpoint, the channel type (HTTP or TCP) to use for communications, and the formatter type to use for message formatting. After constructing the client application, you should be able to run it and invoke the remoting server's GetHelloWorld method.

You now have a working remoting application, and you're ready to add in the custom sink and sink provider to save the incoming message contents using the remoting framework's extensibility.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap