.NET Remoting的新特性-IpcChannel(.NET Framework 2.0)
生活随笔
收集整理的这篇文章主要介绍了
.NET Remoting的新特性-IpcChannel(.NET Framework 2.0)
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
.NET FrameWoek2.0中,新添加一个IpcChannel,它是利用Windows的Ipc(进程间通讯)实现的一个Remoting的Channel,它的速度比Http或Tcp的Channel快很多,但它只能被用在本机不同应用程序域之间的通讯,所以,如果我们的客户端有可能与服务器端在同一个机器上运行时,可以通过注册IcpChannel来提高性能。
下面是一个简单的IpcChannel的示例:
Using directives#region Using directives
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Ipc;
#endregion
namespace TestIpcChannel
{
class Program
{
static void Main(string[] args)
{
IpcChannel myChannel = new IpcChannel("test");
ChannelServices.RegisterChannel(myChannel);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemObject), "RemObject.rem", WellKnownObjectMode.SingleCall);
//服务注册结束,下面是客户端代码
RemObject obj = (RemObject)(Activator.GetObject(typeof(RemObject), "Ipc://Test/RemObject.rem"));
obj.TestMethod();
Console.ReadLine();
}
}
public class RemObject : MarshalByRefObject
{
public void TestMethod()
{
Console.WriteLine("Hello IcpChannel!");
}
}
}
为了便于大家读代码,该程序同时扮演服务器和客户端的角色,可以直接编译执行。
下面是一个简单的IpcChannel的示例:
Using directives#region Using directives
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Ipc;
#endregion
namespace TestIpcChannel
{
class Program
{
static void Main(string[] args)
{
IpcChannel myChannel = new IpcChannel("test");
ChannelServices.RegisterChannel(myChannel);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemObject), "RemObject.rem", WellKnownObjectMode.SingleCall);
//服务注册结束,下面是客户端代码
RemObject obj = (RemObject)(Activator.GetObject(typeof(RemObject), "Ipc://Test/RemObject.rem"));
obj.TestMethod();
Console.ReadLine();
}
}
public class RemObject : MarshalByRefObject
{
public void TestMethod()
{
Console.WriteLine("Hello IcpChannel!");
}
}
}
为了便于大家读代码,该程序同时扮演服务器和客户端的角色,可以直接编译执行。
转载于:https://www.cnblogs.com/dahuaidan410/archive/2004/09/10/41726.html
总结
以上是生活随笔为你收集整理的.NET Remoting的新特性-IpcChannel(.NET Framework 2.0)的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 愈学习愈发现自己的无知
- 下一篇: ASP.NET设置ie打印两法 (精)(