下面是一个简单的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!");
}
}
}
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!");
}
}
}