青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

twzheng's cppblog

『站在風口浪尖緊握住鼠標旋轉!』 http://www.cnblogs.com/twzheng

  C++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
  136 隨筆 :: 78 文章 :: 353 評論 :: 0 Trackbacks
.NET Remoting
By Mark Strawmyer 

[源] http://www.developer.com/net/cplus/article.php/10919_1479761_1

The last two Nuts and Bolts articles focused on database related topics. This month we'll change gears and focus on something different. The focus of this month's article will be .NET remoting. We'll discuss what is .NET Remoting, how it compares to DCOM and Web services, and go through an example.

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 COM

In 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 Services

Unless 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.

Channels

Remote objects are accessed through Channels. Channels physically transport the messages to and from remote objects. There are two existing channels TcpChannel and HttpChannel. Their names give away the protocols that they use. In addition, the TcpChannel or HttpChannel can be extended, or a new channel created if you determine the existing channels do not meet your needs.

Create a Remotable Object

 

A remotable object is nothing more than an object that inherits from MarshalByRefObject. The following sample demonstrates a simple class to expose the omnipresent hello world. This object exposes a single method HelloWorld that will return a string. The only values that can be returned from methods are the classes in the .NET Framework that are serializable such as string and DataSet. In addition, if you need to return a user-defined object then the object needs to be marked as serializable.

 

Create a new C# class library project. Add a class called SampleObject and put in the following code. Add a reference to System.Runtime.Remoting in the project, otherwise the TcpChannel will not be found. Compile the class to make sure you have everything correct.

using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
namespace CodeGuru.Remoting
{
/// <remarks>
/// Sample object to demonstrate the use of .NET Remoting.
/// </remarks>
public class SampleObject : MarshalByRefObject
{
/// <summary>
/// Constructor
/// </summary> 
public SampleObject()
{
}

/// <summary>
/// Return a hello message
/// </summary>
/// <returns>Hello world message</returns>
public string HelloWorld()
{
return "Hello World!";
}
}
}

Create a Server To Expose the Remotable Object

We need to create a server object that will act as a listener to accept remote object requests. For this example we will use the TCP/IP channel. We first create an instance of the channel and then register it for use by clients at a specific port. The service can be registered as WellKnownObjectMode.SingleCall, which results in a new instance of the object for each client, or as WellKnownObjectMode.Singleton, which results in one instance of the object used for all clients.

It is not necessary to create the server listener if you are planning to use IIS. For obvious reasons, IIS only supports the use of the HttpChannel. Create a virtual directory for your application and then put code to register your service in the Application_Start event.

For our example, we'll go ahead and create a server listener in case you don't have IIS. Since the service needs to be bound to an available port, for our example I chose 8080, which is a port that I know to be unused on my computer. You may need to choose a different port depending upon what ports you have available. To see a list of the used ports on your computer open a command prompt and issue the command "netstat --a". It may produce a long listing so make sure the command prompt buffer sizes are set to allow scrolling. Compile the class to make sure you have everything correct.

Create a new C# console application project. Add a class called SampleServer and paste in the following code. Add a reference to System.Runtime.Remoting in the project, otherwise the TcpChannel will not be found. In addition, add a reference to the project containing the SampleObject, otherwise the code will not compile because it won't know how to find a reference to SampleObject.

using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
namespace CodeGuru.Remoting
{
/// <remarks>
/// Sample server to demonstrate the use of .NET Remoting.
/// </remarks>
public class SampleServer
{
public static int Main(string [] args)
{
// Create an instance of a channel
TcpChannel channel = new TcpChannel(8080);
ChannelServices.RegisterChannel(channel);
// Register as an available service with the name HelloWorld
RemotingConfiguration.RegisterWellKnownServiceType(
typeof(SampleObject),
"HelloWorld",
WellKnownObjectMode.SingleCall );
System.Console.WriteLine("Press the enter key to exit...");
System.Console.ReadLine();
return 0;
}
}
}

Create a Client To Use the Remotable Object

Now that we have our remotable object and a server object to listen for requests, let's create a client to use it. Our client will be very simple. It will connect to the server, create an instance of the object using the server, and then execute the HelloWorld method.

Create a new C# console application project. Add a class called SampleClient and paste in the following code. Add a reference to System.Runtime.Remoting in the project, otherwise the TcpChannel will not be found. In addition, add a reference to the project containing the SampleObject, otherwise the code will not compile because it won't know how to find a reference to SampleObject. Compile the class to make sure you have everything correct.

using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
namespace CodeGuru.Remoting
{
/// <remarks>
/// Sample client to demonstrate the use of .NET Remoting.
/// </remarks>
public class SampleClient
{
public static int Main(string [] args)
{
// Create a channel for communicating w/ the remote object
// Notice no port is specified on the client
TcpChannel chan = new TcpChannel();
ChannelServices.RegisterChannel(chan);
// Create an instance of the remote object
SampleObject obj = (SampleObject) Activator.GetObject(
typeof(CodeGuru.Remoting.SampleObject),
"tcp://localhost:8080/HelloWorld" );
// Use the object
if( obj.Equals(null) )
{
System.Console.WriteLine("Error: unable to locate server");
}
else
{
Console.WriteLine(obj.HelloWorld());
}
return 0;
}
}
}

Test the Remoting Sample

Once you have created the projects and successfully compiled each of them you are ready to try it out. Assuming you chose a free TCP/IP port for the service, start the server executable. After the server successfully starts it will result in a console window being displayed with the message "Press the enter key to exit". The server is listening so you are now ready to run the client. Executing the client should result in "Hello World!" being displayed in a separate console window. The client window will then close while the server remains open and available.

If you have multiple computers available to you on a network you could execute the server on one machine and the client on another just to prove to yourself that it really is remoting. In order to run on separate machines you would need to change the reference to localhost in the sample client to point to the appropriate location.

Summary

.NET Remoting is a powerful way to enable interprocess communication. It is more complicated to program against than Web services. You need to decide for yourself whether your standard architecture is to use .NET Remoting or Web services.

Future Columns

The next column will be on the use of encryption in the .NET framework. We'll take a look at some of the encryption algorithms available in the framework and ways to use them. If you have a particular topic in mind please email me at mstrawmyer@crowechizek.com

About the Author

Mark Strawmyer, MCSD, MCSE (NT4/W2K), MCDBA is a Senior Architect of .NET applications for large and mid-size organizations. Mark is a technology leader with Crowe Chizek in Indianapolis, Indiana. He specializes in architecture, design and development of Microsoft-based solutions. You can reach Mark at mstrawmyer@crowechizek.com.

posted on 2007-05-14 00:30 譚文政 閱讀(726) 評論(0)  編輯 收藏 引用 所屬分類: vc++.net
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            国产精品日本欧美一区二区三区| 国产亚洲制服色| 亚洲黄色一区二区三区| 看片网站欧美日韩| 久久久久久久激情视频| 亚洲国产精品精华液2区45| 女女同性女同一区二区三区91| 久久伊人免费视频| 亚洲欧洲精品一区二区| 日韩视频免费观看高清完整版| 欧美日韩免费观看一区| 亚洲欧美综合精品久久成人| 亚洲欧美色婷婷| 永久免费毛片在线播放不卡| 欧美福利视频网站| 欧美日韩另类在线| 欧美在线免费视频| 美脚丝袜一区二区三区在线观看| 日韩视频免费观看高清在线视频 | 亚洲午夜精品一区二区| 在线一区二区三区四区五区| 国产欧美欧美| 欧美激情一区二区三区不卡| 欧美午夜精品久久久久久浪潮| 欧美自拍丝袜亚洲| 久久午夜视频| 亚洲自啪免费| 久久野战av| 亚洲欧美日韩天堂| 美乳少妇欧美精品| 亚洲欧美日韩中文在线制服| 久久免费偷拍视频| 小黄鸭视频精品导航| 老牛国产精品一区的观看方式| 中国成人在线视频| 久久免费国产精品| 篠田优中文在线播放第一区| 女仆av观看一区| 欧美一区二区三区四区在线观看地址 | av成人激情| 黄色国产精品| 亚洲在线播放| 一本一本久久a久久精品综合麻豆 一本一本久久a久久精品牛牛影视 | 久久午夜精品| 亚洲欧美精品中文字幕在线| 美女诱惑一区| 久久日韩精品| 国产日韩欧美精品在线| 亚洲人成在线观看一区二区| 国产精品一区二区三区乱码| 亚洲人体大胆视频| 亚洲第一页在线| 欧美一区二区三区久久精品| 亚洲欧美日韩在线综合| 欧美人与性动交α欧美精品济南到| 鲁大师影院一区二区三区| 欧美午夜久久久| 亚洲欧洲午夜| 亚洲精品国产精品国产自| 欧美在线欧美在线| 欧美一区二区播放| 国产精品久久久久久模特| 夜夜嗨av一区二区三区中文字幕 | 亚洲激情成人| 免费一级欧美片在线播放| 久久久另类综合| 国产一区91| 午夜视频一区二区| 久久国产视频网| 国产欧美一区二区三区在线老狼| 中文国产一区| 欧美伊人久久久久久久久影院| 国产精品试看| 亚洲欧美日韩国产精品| 欧美一区二区在线看| 久久riav二区三区| 国产精品私人影院| 亚洲欧美一区二区精品久久久| 欧美中文在线字幕| 国内自拍亚洲| 免费观看日韩| 亚洲国产乱码最新视频| 国产精品99久久久久久www| 欧美日韩亚洲国产一区| 在线视频你懂得一区| 欧美在线播放| 激情小说亚洲一区| 蜜臀va亚洲va欧美va天堂| 亚洲激情一区| 午夜在线不卡| 亚洲承认在线| 欧美日韩午夜剧场| 欧美一区二区三区电影在线观看| 美女国产一区| 一区二区三区色| 国产精品揄拍一区二区| 久久综合色88| 一本一本久久a久久精品牛牛影视| 午夜在线播放视频欧美| 在线看国产一区| 欧美特黄一区| 看片网站欧美日韩| 亚洲影院高清在线| 欧美激情久久久| 亚洲欧美日韩一区二区三区在线观看 | 亚洲高清一区二| 一区二区三区**美女毛片| 国产精品免费看| 免费成人网www| 亚洲欧美日韩在线观看a三区 | 一区二区毛片| 国产在线成人| 欧美日韩国产限制| 久久成人综合网| 日韩视频一区二区三区| 另类国产ts人妖高潮视频| 亚洲一区二区三区精品视频| 伊人久久成人| 国产精品视频成人| 欧美精品亚洲精品| 久久麻豆一区二区| 亚洲欧美日韩天堂| 亚洲精品久久久久久久久久久久| 久久激情视频久久| 亚洲综合成人在线| aa成人免费视频| 亚洲成人在线| 国产视频在线一区二区| 国产精品xnxxcom| 欧美精品激情在线| 久久人人97超碰精品888| 亚洲欧美视频在线观看视频| 一本大道av伊人久久综合| 亚洲电影av在线| 免费毛片一区二区三区久久久| 久久国产精品久久久久久久久久 | 久久av红桃一区二区小说| 一区二区激情视频| 亚洲人成在线免费观看| 狠狠色狠狠色综合系列| 国产精品亚洲产品| 国产精品视频专区| 国产精品乱码| 国产精品综合网站| 国产人久久人人人人爽| 国产精品嫩草影院一区二区| 国产精品精品视频| 国产精品日韩精品| 国产免费观看久久| 国产欧美日韩综合一区在线观看 | 久久裸体艺术| 久久在线免费| 欧美xxx成人| 欧美精品免费播放| 欧美另类高清视频在线| 欧美日韩国产美女| 国产精品高潮呻吟视频| 国产精品亚洲欧美| 国产一区二区三区高清播放| 激情另类综合| 亚洲激情视频在线| 99国产麻豆精品| 亚洲欧美日韩国产成人精品影院| 午夜视频精品| 久久天堂av综合合色| 欧美电影免费观看高清| 91久久精品国产91性色| 亚洲靠逼com| 亚洲小视频在线观看| 欧美伊人精品成人久久综合97| 久久精视频免费在线久久完整在线看| 久久亚洲免费| 欧美视频一区二区三区…| 国产精品美女久久福利网站| 国产亚洲欧美日韩精品| 亚洲黄色成人久久久| 亚洲视频在线观看免费| 久久久久久久网站| 亚洲黄色尤物视频| 亚洲一区国产| 久久夜色精品国产噜噜av| 欧美日韩一区二区三区免费| 国产一区二区三区日韩欧美| 亚洲精品国产视频| 欧美一级视频一区二区| 欧美国产日韩免费| 亚洲一区二区在线看| 免费久久99精品国产| 国产精品女人久久久久久| 一区二区三区在线免费视频| 亚洲视频你懂的| 暖暖成人免费视频| 亚洲——在线| 欧美国产视频在线观看| 国产亚洲一级高清| 一区二区三区欧美在线| 猫咪成人在线观看| 亚洲欧美日韩国产另类专区| 欧美成人午夜免费视在线看片| 国产一区在线视频|