.NET Remoting Basic(10)-创建不同宿主的客户端与服务器端
2010-08-26 23:00
519 查看
除了控制台之外,现有.net 客户端分为asp.net,WinForm和WPF,Silverlight则无权限直接访问.不过本质流程是相同的.
1.配置文件
2.[b]Server端代码初始化[/b]
3.客户端
3.1配置文件
3.2客户端测试
二.以WinForm为客户端
服务器端如上不变
1.配置客户端初始化
2.UI界面
三.以ASP.NET为客户端
1.将配置文件配置在web.config中
2.在Global.asax的ApplicationStart事件中初始化客户端
四.以ASP.NET为服务器端
web容易部署,可以直接部署在IIS上
1.配置一个xml文件,如RemotingClient.config
2.在Global.asax的ApplicationStart事件中初始化服务器端
访问可以用控制台,WinForm,ASP.NET兼可
一.控制台
一直以来都是以控制台来演示。为保持完整性,重新来一遍.1.配置文件
<?xml version="1.0" encoding="utf-8" ?> <configuration> <system.runtime.remoting> <application> <channels> <channel ref="tcp" port="1234"> <serverProviders> <formatter ref="binary" /> </serverProviders> </channel> </channels> <service> <wellknown type="Server.ServerImpl, Server" objectUri="MyServer.rem" mode="Singleton" /> </service> </application> </system.runtime.remoting> </configuration>
2.[b]Server端代码初始化[/b]
[STAThread] static void Main(string[] args) { System.Console.WriteLine("Starting server..."); RemotingConfiguration.Configure("Server.exe.config"); System.Console.WriteLine("Server configured, waiting for requests!"); System.Console.ReadLine(); } }
3.客户端
3.1配置文件
<configuration> <system.runtime.remoting> <application name="FirstServer"> <channels> <channel ref="tcp" /> </channels> <client> <wellknown type="General.IRemoteFactory, General" url="tcp://localhost:1234/MyServer.rem" /> </client> </application> </system.runtime.remoting> </configuration>
3.2客户端测试
[STAThread] static void Main(string[] args) { System.Console.WriteLine("Configuring client..."); RemotingConfiguration.Configure("ConsoleClient.exe.config"); System.Console.WriteLine("Calling server 1..."); IRemoteFactory factory = (IRemoteFactory)RemotingHelper.CreateProxy(typeof(IRemoteFactory)); Person p = factory.GetPerson(); System.Console.WriteLine(">> Person retrieved: {0} {1}, {2}", p.Firstname, p.Lastname, p.Age.ToString()); System.Console.WriteLine(); Console.ReadLine(); }
二.以WinForm为客户端
服务器端如上不变
1.配置客户端初始化
public class WinApplication { private static IRemoteFactory _factory = null; public static IRemoteFactory ServerProxy { get { if(_factory == null) { _factory = (IRemoteFactory)RemotingHelper.CreateProxy(typeof(IRemoteFactory)); } return _factory; } } public static void Main(string[] args) { // First of all configure remoting services RemotingConfiguration.Configure("WinClient.exe.config"); // Create the windows form and start message looping Application.Run(new MainForm()); } }
2.UI界面
private void ActionCall_Click(object sender, System.EventArgs e) { // Get the transparent proxy for the factory IRemoteFactory proxy = WinApplication.ServerProxy; Person p = proxy.GetPerson(); TextResults.AppendText( string.Format("{0} {1}, {2}\r\n", p.Firstname, p.Lastname, p.Age)); }
三.以ASP.NET为客户端
1.将配置文件配置在web.config中
2.在Global.asax的ApplicationStart事件中初始化客户端
protected void Application_Start(Object sender, EventArgs e) { // Configure the remoting server RemotingConfiguration.Configure(Server.MapPath("web.config")); }
四.以ASP.NET为服务器端
web容易部署,可以直接部署在IIS上
1.配置一个xml文件,如RemotingClient.config
2.在Global.asax的ApplicationStart事件中初始化服务器端
protected void Application_Start(Object sender, EventArgs e) { RemotingConfiguration.Configure(Server.MapPath("RemotingClient.config")); }
访问可以用控制台,WinForm,ASP.NET兼可
相关文章推荐
- 使用ASP.NET AJAX异步调用Web Service和页面中的类方法(10):服务器端和客户端数据类型的自动转换:以XML方式序列化数据、小结
- Validation in .NET 服务器端和客户端的Trigger不同
- 使用ASP.NET AJAX异步调用Web Service和页面中的类方法(10):服务器端和客户端数据类型的自动转换:以XML方式序列化数据、小结
- .NET Remoting Basic(4)-客户端调用方式
- 黑马程序员--10.网络编程--07.【C_S编程中服务器端和客户端的读写流】【C_S常见的“双卡”现象和解决--TCP文本转换器示例】【TCP文本转换器客户端和服务器端循环结束分析】【网络流简化】
- 使用ASP.NET AJAX异步调用Web Service和页面中的类方法(6):服务器端和客户端数据类型的自动转换:复杂类型
- Visual Studio 2008开发新特性系列课程(10):使用Visual Studio 2008和.NET Compact Framework 3.5创建Mobile应用程序
- ASP.NET----获取客户端浏览器信息,获取服务器端主机名和 IP
- 新瓶旧酒ASP.NET AJAX(10) - 客户端脚本编程(Sys.Services命名空间下的类)
- .NET服务器端按钮在客户端点击后禁用,服务端执行完事件后再次激活
- 创建以Microsoft .NET Remoting为基础的分布式应用架构
- 典型的同步客户端、服务器端套接字的创建
- Servlet课程0426(九)Servlet服务器端创建Cookie和客户端读取Cookie
- .NET Remoting——practice & progress(3):Client Activated客户端激活
- cache:缓存在asp.net中如何管理?服务器端缓存?Session, Application, Cache objectscache ,客户端缓存?Cookies,ViewState (转)
- 客户端调用服务器端方法——ASP.NET AJAX(Atlas)、Anthem.NET和Ajax.NET Professional实现之小小比较
- asp.net中服务器端控件和客户端控件的交互问题
- 使用ASP.NET AJAX异步调用Web Service和页面中的类方法(7):服务器端和客户端数据类型的自动转换:泛型集合类型
- ACE学习之创建简单的服务器端和客户端