应用框架的设计与实现——.NET平台4.2代码测试
2006-12-07 19:50
741 查看
.NET远程对象:
激活方式『服务器激活、客户端激活』
类似于:聊天室客服、电话客服
服务器激活『单体、单一调用』
单体方式:服务器端的一个远程对象为所有的请求服务;
单一调用:服务器为每次请求生成一个新对象来提供服务,只为一次调用服务,为一个方法调用服务;
如果客户端持有远程对象代理就可以对同一远程对象多次调用。
==============================================================================
应用框架的设计与实现——.NET平台(4)
4.2.3 .NET Remoting 实例
参照编码,执行代码:
using System;
using System.Collections.Generic;
using System.Text;
namespace BusinessObjectLibrary
{
public class BusinessObject
{
public string hi()
{
return "Hello World! (server)";
}
}
}
服务器端:
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Remoting;
using BusinessObjectLibrary;
namespace ServerPrj
{
public class Class1
{
public static void Main()
{
RemotingConfiguration.Configure("ServerPrj.exe.config");
Console.WriteLine("Press enter to exit the application");
Console.ReadLine();
}
}
}
配置文件:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.runtime.remoting>
<application>
<service>
<wellknown
mode="Singleton"
type="BusinessObjectLibrary.BusinessObject,BusinessObjectLibrary"
objectUri="BusinessObject.rem" />
</service>
<channels>
<channel ref="http" port="8989"/>
</channels>
</application>
</system.runtime.remoting>
</configuration>
客户端:
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Runtime.Remoting;
using BusinessObjectLibrary;
namespace Clientproj
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
//Application.Run(new Form1());
RemotingConfiguration.Configure("Clientproj.exe.config");
BusinessObject bo = new BusinessObject();
MessageBox.Show(bo.hi());
}
}
}
配置文件:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.runtime.remoting>
<application name="Client">
<client>
<wellknown url="http://localhost:8989/BusinessObject.rem"
type="BusinessObjectLibrary.BusinessObject, BusinessObjectLibrary" />
</client>
</application>
</system.runtime.remoting>
</configuration>
编译执行结果:试验失败。
客户端取得的结果是从本地加载执行的,不是服务器端提供的服务。
问题:如何知道服务器端提供哪些服务?如何请求这些服务?如何确定客户端获得服务端的服务了?
激活方式『服务器激活、客户端激活』
类似于:聊天室客服、电话客服
服务器激活『单体、单一调用』
单体方式:服务器端的一个远程对象为所有的请求服务;
单一调用:服务器为每次请求生成一个新对象来提供服务,只为一次调用服务,为一个方法调用服务;
如果客户端持有远程对象代理就可以对同一远程对象多次调用。
==============================================================================
应用框架的设计与实现——.NET平台(4)
4.2.3 .NET Remoting 实例
参照编码,执行代码:
using System;
using System.Collections.Generic;
using System.Text;
namespace BusinessObjectLibrary
{
public class BusinessObject
{
public string hi()
{
return "Hello World! (server)";
}
}
}
服务器端:
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Remoting;
using BusinessObjectLibrary;
namespace ServerPrj
{
public class Class1
{
public static void Main()
{
RemotingConfiguration.Configure("ServerPrj.exe.config");
Console.WriteLine("Press enter to exit the application");
Console.ReadLine();
}
}
}
配置文件:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.runtime.remoting>
<application>
<service>
<wellknown
mode="Singleton"
type="BusinessObjectLibrary.BusinessObject,BusinessObjectLibrary"
objectUri="BusinessObject.rem" />
</service>
<channels>
<channel ref="http" port="8989"/>
</channels>
</application>
</system.runtime.remoting>
</configuration>
客户端:
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Runtime.Remoting;
using BusinessObjectLibrary;
namespace Clientproj
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
//Application.Run(new Form1());
RemotingConfiguration.Configure("Clientproj.exe.config");
BusinessObject bo = new BusinessObject();
MessageBox.Show(bo.hi());
}
}
}
配置文件:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.runtime.remoting>
<application name="Client">
<client>
<wellknown url="http://localhost:8989/BusinessObject.rem"
type="BusinessObjectLibrary.BusinessObject, BusinessObjectLibrary" />
</client>
</application>
</system.runtime.remoting>
</configuration>
编译执行结果:试验失败。
客户端取得的结果是从本地加载执行的,不是服务器端提供的服务。
问题:如何知道服务器端提供哪些服务?如何请求这些服务?如何确定客户端获得服务端的服务了?
相关文章推荐
- 应用框架的设计与实现——.NET平台4.2代码测试问题解决
- 应用框架的设计与实现——.NET平台(4.2 Remoting 客户端激活)
- 应用框架的设计与实现——.NET平台(9 消息队列服务代码分析)
- 应用框架的设计与实现——.NET平台(8.3 源码分析)
- 应用框架的设计与实现——.NET平台(4.3 SAF代码分析)
- 应用框架的设计与实现——.NET平台(10 授权服务.CodeAccessSecurityAttribute)
- 应用框架的设计与实现——.NET平台(6.3.1访问集中式配置.WebService)
- 应用框架的设计与实现——.NET平台(4.2 Remoting 无配置文件)
- 应用框架的设计与实现——.NET平台(10 授权服务.PrincipalPermissionAttribute)
- 微信公共服务平台开发(.Net 的实现)13-------网页授权(下 :C#代码的实现 )
- 应用框架的设计与实现——.NET平台(3)
- 应用框架的设计与实现——.NET平台(8.1 Windows服务.线程)
- ASP.NET设计网络硬盘之查看文件夹实现代码
- 微信公共服务平台开发(.Net 的实现)13-------网页授权(下 :C#代码的实现 )
- Windows平台下程序日志的设计和实现(下:代码)
- 微信公共服务平台开发(.Net 的实现)13-------网页授权(下 :C#代码的实现 )
- asp.net导出excel-一行代码实现excel、xml、pdf、word、html、csv等7种格式文件导出功能而且美观-SNF快速开发平台
- Visual Studio 实现 编写一套.net代码,同时编译到 多个平台,多版本的操作笔记
- 应用框架的设计与实现——.NET平台(10 授权服务.CodeAccessSecurityAttribute)