(1)了解AOP(面向方向编程,动态代理)的概念。
(2)了解IOC(Inversion Of Control)控制反转的概念。
(3)了解DI(Dependency Injection)依赖注入的概念。
(4)掌握Remoting,类的构造函数,类的属性以及关联类在App.config中的配置方式。
(5)了解需要使用到的相关组件(Spring.Core.dll,Spring.Services.dll,EsBasic.dll,Common.Logging.dll,antlr.runtime.dll)。
服务器端:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core"/>
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" />
</sectionGroup>
</configSections>
<spring>
<context>
<resource uri="config://spring/objects"/>
</context>
<objects http://www.springframework.net">http://www.springframework.net" >
<object name="calculate" type="RemotingInterface.Calculate,RemotingInterface">
</object>
<object name="saoControlService" type="Spring.Remoting.SaoExporter,Spring.Services">
<property name="TargetName" value="calculate" />
<property name="ServiceName" value="Calculate" />
</object>
</objects>
</spring>
<system.runtime.remoting>
<application>
<channels>
<channel ref="tcp" port="9000" >
<serverProviders>
<provider ref="wsdl" />
<formatter ref="soap" typeFilterLevel="Full" />
<formatter ref="binary" typeFilterLevel="Full" />
</serverProviders>
<clientProviders>
<formatter ref="binary" />
</clientProviders>
</channel>
</channels>
</application>
</system.runtime.remoting>
</configuration>
启动程序:
//程序启动的时候,初始化Remoting配置
RemotingConfiguration.Configure("ServerRemoting.exe.config");
客户端:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core"/>
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" />
</sectionGroup>
</configSections>
<spring>
<context>
<resource uri="config://spring/objects"/>
</context>
<objects http://www.springframework.net">http://www.springframework.net" >
<object name="frmClient" type="ClientRemoting.frmCaculateClient,ClientRemoting">
<property name="Calculate" ref="remotingCalculate"/>
</object>
<!--访问Remoting ControlService-->
<object name="remotingCalculate" type="Spring.Remoting.SaoFactoryObject, Spring.Services">
<property name="ServiceInterface">
<value>RemotingInterface.ICalculate, RemotingInterface</value>
</property>
<property name="ServiceUrl" value="tcp://服务器的IP:9000/Calculate"/>
</object>
</objects>
</spring>
</configuration>
客户端需要用到的类中:
private ICalculate calculate;
public ICalculate Calculate
{
set
{
calculate = value;
}
}
其他的配置:
<!--默认实现(实现属性方式)-->
<object name="MyDataAccess" type="DataAccessComponent.DefaultDataAccess,DataAccessComponent">
<property name="Connection">
<value>Connection</value>
</property>
</object>
<!--扩展实现(自己设置值)-->
<object name="MyExtendDataAccess" type="ExtendDataAccessComponent.ExtendDataAccess,ExtendDataAccessComponent">
</object>
<!--扩展实现(构造函数)-->
<object name="MyExtendDataAccessStructure" type="ExtendDataAccessComponent.ExtendDataAccess,ExtendDataAccessComponent">
<constructor-arg index="0">
<value>192.168.3.141</value>
</constructor-arg>
</object>
<!--扩展实现(构造函数)-->
<object name="MyDog" type="DataAccessComponent.Dog,DataAccessComponent">
<constructor-arg index="0">
<value>旺财</value>
</constructor-arg>
<property name="NewFood">
<ref object="Food" />
</property>
</object>
<object name="Food" type="DataAccessComponent.Food,DataAccessComponent">
<constructor-arg index="0">
<value>肉</value>
</constructor-arg>
</object>
</objects>
<!--init-method定义一个方法名,便于类在初始化以后自动调用该程序 -->
<object name="form1" type="Demo.MyServer.Form1 ,Demo.MyServer" init-method="Initialize">
<property name="CenterService" ref="remotingCenterService"/>
<property name="ServerInformation" ref="serverInformation"/>
</object>
(2)了解IOC(Inversion Of Control)控制反转的概念。
(3)了解DI(Dependency Injection)依赖注入的概念。
(4)掌握Remoting,类的构造函数,类的属性以及关联类在App.config中的配置方式。
(5)了解需要使用到的相关组件(Spring.Core.dll,Spring.Services.dll,EsBasic.dll,Common.Logging.dll,antlr.runtime.dll)。
服务器端:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core"/>
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" />
</sectionGroup>
</configSections>
<spring>
<context>
<resource uri="config://spring/objects"/>
</context>
<objects http://www.springframework.net">http://www.springframework.net" >
<object name="calculate" type="RemotingInterface.Calculate,RemotingInterface">
</object>
<object name="saoControlService" type="Spring.Remoting.SaoExporter,Spring.Services">
<property name="TargetName" value="calculate" />
<property name="ServiceName" value="Calculate" />
</object>
</objects>
</spring>
<system.runtime.remoting>
<application>
<channels>
<channel ref="tcp" port="9000" >
<serverProviders>
<provider ref="wsdl" />
<formatter ref="soap" typeFilterLevel="Full" />
<formatter ref="binary" typeFilterLevel="Full" />
</serverProviders>
<clientProviders>
<formatter ref="binary" />
</clientProviders>
</channel>
</channels>
</application>
</system.runtime.remoting>
</configuration>
启动程序:
//程序启动的时候,初始化Remoting配置
RemotingConfiguration.Configure("ServerRemoting.exe.config");
客户端:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core"/>
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" />
</sectionGroup>
</configSections>
<spring>
<context>
<resource uri="config://spring/objects"/>
</context>
<objects http://www.springframework.net">http://www.springframework.net" >
<object name="frmClient" type="ClientRemoting.frmCaculateClient,ClientRemoting">
<property name="Calculate" ref="remotingCalculate"/>
</object>
<!--访问Remoting ControlService-->
<object name="remotingCalculate" type="Spring.Remoting.SaoFactoryObject, Spring.Services">
<property name="ServiceInterface">
<value>RemotingInterface.ICalculate, RemotingInterface</value>
</property>
<property name="ServiceUrl" value="tcp://服务器的IP:9000/Calculate"/>
</object>
</objects>
</spring>
</configuration>
客户端需要用到的类中:
private ICalculate calculate;
public ICalculate Calculate
{
set
{
calculate = value;
}
}
其他的配置:
<!--默认实现(实现属性方式)-->
<object name="MyDataAccess" type="DataAccessComponent.DefaultDataAccess,DataAccessComponent">
<property name="Connection">
<value>Connection</value>
</property>
</object>
<!--扩展实现(自己设置值)-->
<object name="MyExtendDataAccess" type="ExtendDataAccessComponent.ExtendDataAccess,ExtendDataAccessComponent">
</object>
<!--扩展实现(构造函数)-->
<object name="MyExtendDataAccessStructure" type="ExtendDataAccessComponent.ExtendDataAccess,ExtendDataAccessComponent">
<constructor-arg index="0">
<value>192.168.3.141</value>
</constructor-arg>
</object>
<!--扩展实现(构造函数)-->
<object name="MyDog" type="DataAccessComponent.Dog,DataAccessComponent">
<constructor-arg index="0">
<value>旺财</value>
</constructor-arg>
<property name="NewFood">
<ref object="Food" />
</property>
</object>
<object name="Food" type="DataAccessComponent.Food,DataAccessComponent">
<constructor-arg index="0">
<value>肉</value>
</constructor-arg>
</object>
</objects>
<!--init-method定义一个方法名,便于类在初始化以后自动调用该程序 -->
<object name="form1" type="Demo.MyServer.Form1 ,Demo.MyServer" init-method="Initialize">
<property name="CenterService" ref="remotingCenterService"/>
<property name="ServerInformation" ref="serverInformation"/>
</object>
本文介绍了Spring框架中Remoting的配置方法,包括服务器端与客户端的XML配置示例,展示了如何通过配置文件来实现远程服务的发布与调用。

2301

被折叠的 条评论
为什么被折叠?



