简单Remoting例子
来源:互联网 发布:淘宝客户端删除评价 编辑:程序博客网 时间:2024/06/07 06:56
参考MSDN给出的例子
包含Remoting两种协议(tcp,http)的代码,其中在RemoteObject类添加数据访问的代码,则可实现NET Framwork间的简单分布式数据库程序。
1.服务端:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Channels.Http;
using System.Security.Permissions;
using RemotingModel;
namespace RemotingServer
{
class Program
{
[SecurityPermission(SecurityAction.Demand)]
static void Main(string[] args)
{
//TcpServer();
HttpServer();
}
private static void TcpServer()
{
TcpChannel serverChannel = new TcpChannel(9090);
ChannelServices.RegisterChannel(serverChannel, false);
ChannelDataStore data = (ChannelDataStore)serverChannel.ChannelData;
RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemoteObject), "RemoteObject.rem", WellKnownObjectMode.Singleton);
Console.WriteLine("Press ENTER to exit the server.");
Console.ReadLine();
}
private static void HttpServer()
{
HttpChannel serverChannel = new HttpChannel(9090);
ChannelServices.RegisterChannel(serverChannel,false);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemoteObject), "RemoteObject.rem", WellKnownObjectMode.Singleton);
Console.WriteLine("Press ENTER to exit the server.");
Console.ReadLine();
}
}
}
2.客户端
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Permissions;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Channels.Http;
using RemotingModel;
using System.Runtime.Remoting.Messaging;
namespace RemotingClient
{
class Program
{
[SecurityPermission(SecurityAction.Demand)]
static void Main(string[] args)
{
//TcpClient();
HttpClient();
}
private static void TcpClient()
{
TcpChannel clientChannel = new TcpChannel();
ChannelServices.RegisterChannel(clientChannel,false);
WellKnownClientTypeEntry remoteType = new WellKnownClientTypeEntry(typeof(RemoteObject), "tcp://localhost:9090/RemoteObject.rem");
RemotingConfiguration.RegisterWellKnownClientType(remoteType);
RemoteObject service = new RemoteObject();
Console.WriteLine("The remote object has been called {0} times.", service.GetCount());
}
private static void HttpClient()
{
HttpClientChannel clientChannel = new HttpClientChannel();
ChannelServices.RegisterChannel(clientChannel,false);
WellKnownClientTypeEntry remoteType = new WellKnownClientTypeEntry(typeof(RemoteObject),"http://localhost:9090/RemoteObject.rem");
RemotingConfiguration.RegisterWellKnownClientType(remoteType);
RemoteObject service = new RemoteObject();
Console.WriteLine("The remote object has been called {0} times.", service.GetCount());
}
}
}
3.对象类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Remoting;
namespace RemotingModel
{
public class RemoteObject : MarshalByRefObject
{
private int callCount = 0;
public int GetCount()
{
callCount++;
return (callCount);
}
}
}
- 简单Remoting例子(1)
- Spring remoting简单例子
- 简单Remoting例子
- 一个简单的.net remoting客户端例子
- 最简单的remoting的例子
- 一个简单的.net remoting客户端例子
- C# Remoting的一个简单例子
- C# Remoting的一个简单例子
- C# Remoting的一个简单例子
- C# Remoting的一个简单例子
- remoting例子
- .net Remoting简单实例
- .net Remoting 简单范例
- .net Remoting简单实例
- .net Remoting简单实例
- Remoting简单实例[]
- Remoting 简单应用
- Remoting简单实例
- Objective-C @encode关键字
- 软声级计如何选麦克风
- cygwin jni 报错 '__int64' does not name a type error: 'jlong' does not name a type
- icinga简明教程3—icinga安装nagiosQL插件用于配置
- 第三章 控制器的实现(一)
- 简单Remoting例子
- dts解析过程
- lamp环境搭建
- python27 mysql win7扩展安装 使用
- 基于Android平台的ToDoList APP
- MySql获取系统时间
- Linux的五个查找命令
- cocos2dx进阶学习之CCSpriteBatchNode
- ant build.xml中classpath