![]() |
|
|
.NET Remoting
You can access remote components by using .NET Remoting. You can create application that accesses the remote components by using TCP or HTTP channeling. In addition to this method, .NET provides various other types of remoting suited for diff requirements. The reason for discussing remoting is more important when you consider today’s enterprise environment. While developing enterprise application, your requirements might vary based on the methods of accessing the components. As a developer, you would need to access components in a way where in there is more control on the security. However, as an end user, you would mostly access the component through the web. Remote Components Any component that inherits from MarshalByRefObject can be accessed remotely. There are 4 ways of accessing remote components, they are
Here we will discuss about HTTP Channel HTTP Channel A channel is an object that allows communication between a client and the remote component across application boundaries. Both the TCP and HTTP channels implement the client and the server channels. Though the code might appear similar, the difference lies in the underlying protocols. The HTTP channel as suggested by the name uses the HTTP protocol. This channel uses the SOAP formatter, which encodes the communications as XML. Though binary formatter can also be used, it is not preferred. The SOAP formatter encoded XML is just plain text. Therefore, the SOAP formatters provide a better solution in case your network has firewalls or some other network security. Use of HTTP Channel is preferred for Internet Communication. This is because the underlying protocol, HTTP, is a stateless protocol and provides scalability. In addition, SOAP is one of the best interoperable and integrated protocols.
The above diagram depicts channeling irrespective of the protocol used. When the client calls a remote method, the proxy locates the channel and passes the message. The channels in turn encode the message based on the protocol used. For example, the channel uses SOAP to encode the message for an HTTP channel. At the server end, the message is decoded and passed to the Dispatcher, which looks for the appropriate method and invoke it. If the method is not found, an exception is raised.
The above diagram depicts how a call is made to the server. The Activator.GetObject method creates a proxy for the Remote Object as a well known object. The GetObject method in turn calls the RemotingService.connect methods to get the proxy of the well known server object. The server registers the channel to listen at a certain port. For example, in this diagram the HTTP server objects register the channel to listen at port 9932. The connect method passes the message through the channel registered at port 9932. The server object are all well known objects, which means a table similar to the identity table shown in the diagram is maintained so that the object can be resolved by the well known names. The server objects then execute the methods called and the result is sent back through the same channel to the client, Note that the communication is between application domains. The steps to create a remote communication using HTTP Channel 1. You need to create the remote object. To code the remote object, you need to create a class that inherits from the System.MarshalByRefObject class. For example, to create a class, TestLoader as remote object, You need to specify : Public class TestLoader : System.MarshalByRefObject After creating the class, you can write methods as per your requirements inside this class. 2. Next, you need to write the code for the HTTP Server. To code the HTTP Server, you need to create a console application and add reference to the System.Runtime.Remoting dll. This gives you the System.Runtime.Remoting.Channels.Http class. For example, to create a new HttpChannel that listen on 9932 port, you need to specify: HttpServerChannel channel=new HttpServerChannel (9932); After creating an HTTP channel, you need to register the channel using: ChannelService.RegisterChannel (channel); After registering the channel, you need to make the channel available by registering it as a well known service. This makes the remote object available when the client calls the Activator.GetObject method as given below RemotingConfiguration.RegisterWellKnownServiceType (typeof (TestLoader),”TestLoader”, WellKnownObjectMode, SingleCall); 3 . After creating the server, you need to write the code for the client. The client first register an HttpClientChannel by using: ChannelServices.RegisterChannel(new HttpClientChannel()); The client gets the proxy using the Activator object by using: TestLoader loader = (TestLoader) Activator.GetObject (typeof (RemoteTest.TestLoader),http://localhost:9932/TestLoader); Now, calls can be made to the remote objects methods that are available using the loader object.
|
|
@sathiyasivam@gmail.com |