Technology Towards Microsoft Headlines

Tuesday, August 26, 2008

MICROSOFT .NET REMOTING AND WEB SERVICES

.Net Remoting and WebServices

.NET remotingWhile Web services are arguably the best way for clients outside of your organisation to access components, what about components within your organisation? Many companies are building Web services and using them internally. There is nothing wrong with this approach, but it doesn't provide the best performance. If components are created in .NET and the client applications are .NET, you can place components on shared servers and access them via remoting.Remoting is the .NET technology that replaces DCOM allowing you to communicate between a client application and components in a binary format. As a result, remotable components are faster than Web services. However, creating remotable components is more difficult because you must add additional code to your components. This code isn't much more complicated than its Web service counterpart, but you cannot directly instantiate a remote component. Instead, you must create a host application that instantiates the component and listens for requests. The good news is that this host can be a Windows service, a Windows application, a console application, or anything that can run and hold the object open.Not only do you have to create a host application, you must also make several decisions about the remotable object, such as which channel to use. .NET supports both HTTP and TCP channels. The HTTP channel actually uses the SOAP protocol to transport messages to and from remotable objects; this means all messages are serialised to XML. The TCP channel uses a binary stream to transport the messages.Next, you must choose between two activation modes: Singleton and SingleCall. Singleton types have only one instance of an object at any time. All client requests are serviced by that single instance. This allows you to "share" data between requests or, more likely, maintain state between requests. SingleCall types, on the other hand, create a new instance of the object for each client request. SingleCall objects are more like Web services because they are stateless and are created and destroyed for each request..NET is architected in such a way that remotable components can change channels without being recompiled. You can place the channel information in a configuration file and change from TCP to HTTP or vice versa without recompiling the application. Similarly, you can change a configuration file for the client to match the channel that the host is using.Quick code comparisonsThe entire code for the Web service follows:Imports System.Web.ServicePublic Class ConvertMoneyInherits WebServicePublic Function _PoundsToDollars(BritishPounds As Double) As DoubleReturn BritishPounds * 1.44End FunctionEnd ClassHere is the code to implement the same thing with a remotable component:Public Class ConvertMoneyInherits System.MarshalByRefObjectPublic Function _PoundsToDollars(ByVal BritishPounds As Double) As DoubleReturn BritishPounds * 1.44End FunctionEnd ClassThe component looks simpler. In fact, the only difference is that it inherits from System.MarshalByRefObject. But remember, you need to build a host application that instantiates the object and listens for requests. The code for the host object could look like this:Imports System.Runtime.RemotingImports System.Runtime.Remoting.ChannelsImports System.Runtime.Remoting.Channels.TcpImports RemoteConvertMoneyModule Module1Sub Main()Dim tcpChannel As New TcpChannel(7777)ChannelServices.RegisterChannel(tcpChannel)Dim ChangeMoney As New ConvertMoneyRemotingServices.Marshal(ChangeMoney, "ConvertMoney")Console.ReadLine()End SubEnd ModuleIn this case, the host application is a console application. You start the application and it launches a console application and creates the object. The console application runs until someone presses the [Enter] key, and the object is available until needed.As you can see, the amount of work required to create the remotable component is more than the Web service.Make the choiceThere is no absolute answer to whether you should choose Web services or remoting in most cases. If your entire distributed application is inside your organisation firewall and performance is critical, remoting via the TCP channel is the best choice. If the entire application is inside the firewall and performance isn't as critical, or if you want to keep things as simple as possible, Web services is a better choice.But, if you need to allow access to clients other than .NET, you'll need to use Web services regardless of whether or not the client is inside or outside the firewall. In the end, the choice is left to the developer, so you'll need thorough knowledge of both technologies to make a proper decision.What is .Net Remoting?.NET Remoting is an enabler for application communication. It is a generic system for different applications to use to communicate with one another. .NET objects are exposed to remote processes, thus allowing interprocess communication. The applications can be located on the same computer, different computers on the same network, or even computers across separate networks..NET remoting versus Distributed COMIn the past interprocess communication between applications was handled through Distributed COM, or DCOM. DCOM works well and the performance is adequate when applications exist on computers of similar type on the same network. However, DCOM has its drawbacks in the Internet connected world. DCOM relies on a proprietary binary protocol that not all object models support, which hinders interoperability across platforms. In addition, have you tried to get DCOM to work through a firewall? DCOM wants to communicate over a range of ports that are typically blocked by firewalls. There are a ways to get it to work, but they either decrease the effectiveness of the firewall (why bother to even have the firewall if you open up a ton of ports on it), or require you to get a firewall that allows support for binary traffic over port 80..NET Remoting eliminates the difficulties of DCOM by supporting different transport protocol formats and communication protocols. This allows .NET Remoting to be adaptable to the network environment in which it is being used. .NET Remoting versus Web ServicesUnless you have been living in a cave, or are way behind in your reading, you have probably read something about Web services. When you read the description of .NET Remoting it may remind you a lot of what you're read about Web services. That is because Web services fall under the umbrella of .NET Remoting, but have a simplified programming model and are intended for a wide target audience. Web services involve allowing applications to exchange messages in a way that is platform, object model, and programming language independent. Web services are stateless and know nothing about the client that is making the request. The clients communicate by transferring messages back and forth in a specific format known as the Simple Object Access Protocol, or SOAP. (Want to get some funny looks in the hallway? Stand around in the hallway near the marketing department with your colleagues and discuss the benefits of using SOAP). The following list outlines some of the major differences between .NET Remoting and Web services that will help you to decide when to use one or the other: · ASP.NET based Web services can only be accessed over HTTP. .NET Remoting can be used across any protocol.· Web services work in a stateless environment where each request results in a new object created to service the request. .NET Remoting supports state management options and can correlate multiple calls from the same client and support callbacks.· Web services serialize objects through XML contained in the SOAP messages and can thus only handle items that can be fully expressed in XML. .NET Remoting relies on the existence of the common language runtime assemblies that contain information about data types. This limits the information that must be passed about an object and allows objects to be passed by value or by reference.· Web services support interoperability across platforms and are good for heterogeneous environments. .NET Remoting requires the clients be built using .NET, or another framework that supports .NET Remoting, which means a homogeneous environment.

No comments:

Page copy protected against web site content infringement by Copyscape

Subscribe To Get Updates Directly To Your E-Mail

Enter your email address:

Delivered by FeedBurner