![]() |
.NET: Using Remoting in .NET |
Search [dghifccd] |
|
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Other Xoc managed sites: http://grr.xoc.net http://www.986faq.com http://www.mayainfo.org https://mayacalendar.xoc.net http://www.yachtslog.com |
While Web Services are getting all the attention in .NET, there are other techniques that it supports that are more efficient for communicating between processes. The advantage of a Web Service is that it is a platform neutral mechanism that uses SOAP as the transport mechanism. However, if you are in control of both sides of the communication between processes, it is more efficient to use Remoting. As an example, I use Remoting as the mechanism for having an ASP.NET page talk to a Windows Service. The basic idea is that you register a TCP channel on one side of the communications, then register a class as a well-known service type. From the other side you can instantiate the class and do things to it. The two processes can be running on the same machine, or they could be on different machines that have tcp access to each other. So if you have one process running, it can run this code to register MyClass on tcp port 8040. The port is just an arbitrary high number that you use on both sides of the conversation: chan = new TcpChannel(8040); ChannelServices.RegisterChannel(chan); RemotingConfiguration.RegisterWellKnownServiceType( typeof(MyNameSpace.MyClass), "MyClass", WellKnownObjectMode.Singleton); You will also need a class, in this case called MyClass. This class will need to inherit MarshalByRefObject. using System; namespace MyNameSpace { public class MyClass : MarshalByRefObject { public String Check() { return "Success"; } } } On the other side, when you want to call the class, you execute this code: MyClass mc = (MyClass) Activator.GetObject(typeof(MyClass), "tcp://localhost:8040/MyClass"); System.Windows.Forms.MessageBox.Show(mc.Check()) You will need to replace localhost with the domain name or IP address of the machine that you are connecting to if it is not the current machine. If going through a firewall, that port will have to be open. (Web Services go through port 80 by default, so it usually doesn't require any firewall configuration). Also, if any objects are passed back from the call, they need to have the serializable attribute on them. For example, if you had a collection class called Units, you could pass an object created from this class back from a method by declaring the class like this: [Serializable] public class Units : CollectionBase ... |
||
Top |
[www.xoc.net] Copyright © 1997-2023 by Gregory Reddick ![]() |