C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




.Acessing remote components with .NET Remoting


Posted Date: 18 Jul 2006    Resource Type: Articles    Category: WCF/Webservices
Author: sathiyasivamMember Level: Diamond    
Rating: Points: 10



Introduction



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

TCP Channel
HTTP Channel
COM+ Web Services
DCOM Serviced Components

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.

http://sathiyasivam.bizhat.com/dotnet/default_files/image002.gif

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.

http://sathiyasivam.bizhat.com/dotnet/default_files/image004.gif

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.

Summary




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.


Any query regarding this and in details , Please visit the site

http://sathiyasivam.bizhat.com/dotnet/default.htm

And fell free to ask any query .






Responses

Author: Kannapiran    19 Jul 2006Member Level: Bronze   Points : 0
even this article deals with Basics of .net,it more clear and easy to understand..................
it even helped me to solve the bug in my project(very elementary error)....
it would have been very good if more examples are given ,so that it would help lots of youngsters who are new to this language.
anyway good work


Author: Lakhbir Kaur Pannu    15 Aug 2006Member Level: Bronze   Points : 0
Hi,
Actually i was searching on .net remoting and got your article,I am building an application where i need to call a method which is written in a windows application from a asp.net WebApplication,Do you think its possible using remoting as you said the server has to be a console application..... Please help me in this regard ........if its possible then how ?


Author: Lakhbir Kaur Pannu    15 Aug 2006Member Level: Bronze   Points : 0
Hi,
Actually i was searching on .net remoting and got your article,I am building an application where i need to call a method which is written in a windows application from a asp.net WebApplication,Do you think its possible using remoting as you said the server has to be a console application..... Please help me in this regard ........if its possible then how ?


Author: Ahmet Kaymaz    16 Nov 2006Member Level: Bronze   Points : 0
Can you help me about using Remoting with SSL.


C#, Asp.Net, AJAX
http://www.ahmetkaymaz.com


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Secure XML Web Services with Secure Socket Layer
Previous Resource: ASP.NET Webservices - Invoking Webmethods from Remote Machine
Return to Discussion Resource Index
Post New Resource
Category: WCF/Webservices


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use