How to use .Net Remoting Configuration files

 

.NET Remoting configuration files allow you to specify parameters for most aspects of the remoting framework. These files can define tasks as simple as registering a channel and specifying a Type as a server-activated object, or can be as complex as defining a whole chain of IMessageSinks with custom properties.

通过.Net Remoting配置文件可以为Remote Objects设定许多参数,如ChannelSAO服务端激活对象类型(Singleton/SingleCall)等等,方便以后在不用修改代码或重新编译的情况下,改变Remote Objects的行为。

 

1,如下是Server端典型的Remoting配置文件:

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

  <system.runtime.remoting>

    <application>

      <channels>

        <channel ref="http"/>

      </channels>

      <service>

        <wellknown mode="Singleton"

                   type="ComponentHost.CustomerManager, ComponentHost"

                   objectUri="CustomerManager.soap" />

      </service>

 

     </application>

   </system.runtime.remoting>

</configuration>

 

1)当Remote Objects部署在Console/Windows FormWindows Services下时(上面的配置文件channel需要设置port属性),相应Server端声明Remote Objects的代码可以简化为:

string filename = "server.exe.config";

RemotingConfiguration.Configure(filename);

 

2)如果Remote Objects部署在IIS时,根本就不需要任何代码声明。但是需要将上述配置文件命名为:web.config,并且将Remote ObjectsDLL文件安置在web applicationBIN文件夹。

 

一般在实际应用中,基本上将Remote Objects部署在IIS环境中,好处是(I)不需要编写额外的代码;(II)只要启动机器,远程对象就启动了。不需要你半夜三更跑到公司去登录,然后启动发生故障的远程服务;(III)容易与IIS认证服务进行集成;(IV)可能还有更多优点,我现在没有想到。

 

3)如果需要声明多个远程对象,只需要在<service></service>之间添加相应的Remote Objects配置信息即可。

 

4)另外需要注意type属性为:<namespace>.<class>, <assembly>

 

2,如下是Client端典型的配置文件:

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

  <system.runtime.remoting>

    <application>

 

      <client>

        <wellknown type="ComponentHost.CustomerManager, RemotingTest"

                   url="http://localhost/ComponentHost/CustomerManager.soap" />

      </client>

 

    </application>

  </system.runtime.remoting>

</configuration>

 

要注意type属性的设定:<namespace>.<class>, <assembly>

如果Client通过SoapSuds产生Remote Objects的元数据assembly,或者是Shared Assembly(如InterfaceAbstract Class),这里<assembly>则为上述assembly的名称。

如果是通过SoapSuds产生Source code,则<assembly>Client应用程序名(无exe后缀)。

 

同时,Clientapplication调用Remote Objects时,可以省掉:注册通道、Activator.GetObject()/RemotingConfiguration.RegisterActivatedServiceType()等代码,取而代之的代码为:

string filename = “clientApplication.exe.config”;

RemotingConfiguration.Configure(filename);

下面通过new来创建Remote Object实例。

 

3,标准的.Net Remoting Configuration配置文件

MSDN中有.Net Remoting Configuration file中全部元素/属性的完整的详细说明,需要的时候再查阅了。一般情况下,知道下面这些属性就够用了。

<configuration>

   <system.runtime.remoting>

      <application>

        <lifetime /> ―― 配置Remote Objects生存期的信息

        <channels /> ―― 配置与远程对象进行通信的信道

        <service />

        <client />

      </application>

   </system.runtime.remoting>

</configuration>

 

简单说明:

1<service> ―― 仅在Server端配置

      <service>

          <wellknown /> ―― 配置要发布的SAO(已知)对象的信息

          <activated /> ―― 配置要发布的CAO客户端激活对象的信息

      </service>

 

 

2<client> ―― 仅在Client端配置,与Server<service>对应

         <client>

            <wellknown />

            <activated />

        </client>

 

When using CAOs, the <client> property has to specify the URI to the server for all underlying <activated> entries.

NoteWhen using CAOs from more than one server, you have to create several <client> properties in your configuration file.

当调用CAO远程对象时,必须设定<client>url属性。如果CAO来自不同的Server,则需要在配置文件中定义多个<client>。如下所示:

     <client url="http://localhost/MyServer>

        <activated type="Server.MyRemote, Client" />

      </client>

 

4,定制Client/Server Channel元素

1Client Side

<channel ref="http">

    <clientProviders>

          <formatter ref="binary" /> 

    </clientProviders>

</channel>

其中,formatter ref=”binary” or “soap”formatter ref指要在通道上发送的消息格式,在此示例中为二进制,以增强性能。

 

2Server Side

<channel ref="http">

    <serverProviders>

          <provider ref="wsdl" />

          <formatter ref="binary" typeFileterLevel="Full" />

          <formatter ref="soap" typeFileterLevel="Full" />

    </serverProviders>

</channels>  

typeFilterLevel表示当前自动反序列化级别,支持的值包括 Low(默认值)和 Full

 

1. Ingo Rammer, Advanced .Net Remoting.

2. MSDN

 



Reference:
posted on 2004-10-10 13:27 Rickie 阅读(4295) 评论(25)   编辑  收藏 引用 收藏至365Key 所属分类: 1.Remoting技术


#  re: .Net Remoting配置文件的用法 2004-11-04 11:34 Rickie
You are welcome, Casablanca.   回复
  

#  re: .Net Remoting配置文件的用法 2004-11-18 11:34 hjf1223
奇怪啦,我把配置文件放到可执行文件下调试的时候配置文件会被“吃掉”,比如clientApplication.exe.config,可是我把exe删除就可以了!
比如clientApplication.config就可以用了!前段时间也遇到这个问题。   回复
  

#  re: .Net Remoting配置文件的用法 2004-11-18 11:44 Rickie
其实,你只要在project中添加一个app.config文件,编译调试的时候会自动生成 clientApplication.exe.config 文件。   回复
  

#  re: .Net Remoting配置文件的用法 2004-11-24 18:11 Casablanca
无需配置端口吗?那当有多个服务的时候,客户端连接的时候究竟连接哪个端口?或者是不用连接端口,只需要连接ObjectUri?   回复
  

#  re: .Net Remoting配置文件的用法 2004-11-24 20:49 mahope
为什么不可以对同一应用程序同时配置<service />和<client />?
运行时总会有莫名其妙的错误:(
   回复
  

#  re: .Net Remoting配置文件的用法 2004-11-25 01:12 Rickie
To mahope,
*
为什么要对同一应用程序同时配置<service />和<client />?有什么特殊的需求吗?

<service> ―― 仅在Server端配置
<client> ―― 仅在Client端配置,与Server端<service>对应   回复
  

#  re: .Net Remoting配置文件的用法 2004-11-25 01:32 Rickie
To Casablanca,
*
对Server端而言,当然需要指定端口了,否则Client端无法访问.
(1)当Remote Objects部署在Console/Windows Form、Windows Services下时(上面的配置文件channel需要设置port属性)。
<channels>
<channel ref="http" port="8083">
<serverProviders>
<provider ref="wsdl" />
<formatter ref="soap" typeFilterLevel="Full" />
<formatter ref="binary" typeFilterLevel="Full" />
</serverProviders>
</channel>
</channels>
(2)当由IIS承载Remote Objects时,port就是由IIS设定的,默认为80。

那当有多个服务的时候,
看看client端<client>元素配置内容就知道了,如下:
<client>
<wellknown type="ComponentHost.CustomerManager, RemotingTest"
url=" http://localhost/ComponentHost/CustomerManager.soap" />
</client>
url属性中包括http(channel),port(示例为80),Application Name(ComponentHost),服务对象标识(CustomerManager.soap)
**全有了,一个都不能少。
   回复
  

#  re: .Net Remoting配置文件的用法 2004-11-25 17:56 Casablanca
那当IIS承载多个不同的Remote Objects时怎么配置服务器端呢?我看了你的文章,你说在<service></service>中添加多个即可,可是每个service对应的port在哪里设置呢?我试验过,写法:
<service>
<wellknown mode="Singleton" type="ComponentHost.CustomerManager, ComponentHost"
objectUri="CustomerManager.soap" />
</service>
<service>
<wellknown mode="Singleton" type="ComponentHost.CustomerManagerOne, ComponentHost"
objectUri="CustomerManagerOne.soap" />
</service>

<service>
<wellknown mode="Singleton" type="ComponentHost.CustomerManagerTwo, ComponentHost"
objectUri="CustomerManagerTwo.soap" />
</service>

<channels>
<channel ref="http" port="8081">
<serverProviders>
<provider ref="wsdl" />
<formatter ref="soap" typeFilterLevel="Full" />
<formatter ref="binary" typeFilterLevel="Full" />
</serverProviders>
</channel>

<channel ref="http" port="8082">
<serverProviders>
<provider ref="wsdl" />
<formatter ref="soap" typeFilterLevel="Full" />
<formatter ref="binary" typeFilterLevel="Full" />
</serverProviders>
</channel>

<channel ref="http" port="8083">
<serverProviders>
<provider ref="wsdl" />
<formatter ref="soap" typeFilterLevel="Full" />
<formatter ref="binary" typeFilterLevel="Full" />
</serverProviders>
</channel>

</channels>
这样写之后,在配置的时候就出现错误了。我不知道当配置多个服务的时候,在什么位置写每个服务对应的port   回复
  

#  re: .Net Remoting配置文件的用法 2004-11-25 17:59 Casablanca
另外,objectUri="CustomerManager.soap"中的objectUri是不是必须是某个存在的类?   回复
  

#  re: .Net Remoting配置文件的用法 2004-11-26 09:18 Rickie
当IIS承载多个不同的Remote Objects时:
<service>
<wellknown mode="Singleton" type="ComponentHost.CustomerManager, ComponentHost"
objectUri="CustomerManager.soap" />
<wellknown mode="Singleton" type="ComponentHost.CustomerManagerOne, ComponentHost"
objectUri="CustomerManagerOne.soap" />
......
</service>

应该这样配置多个Remote Objects对象。   回复
  

#  re: .Net Remoting配置文件的用法 2004-11-26 09:21 Rickie
(2)当由IIS承载Remote Objects时,port就是由IIS设定的,默认为80。
不要添加port的设置。因此你的配置文件是错误的。
^^^
上面的文章写的还算清楚,仔细看看吧。   回复
  

#  re: .Net Remoting配置文件的用法 2004-11-26 09:26 Rickie
另外,objectUri="CustomerManager.soap"中的objectUri是不是必须是某个存在的类?
***
objectUri="CustomerManager.soap" 只是一个标识而已,不必是某个存在的类,如上面的可以改为objectUri="ILOVEMM.soap"
   回复
  

#  re: .Net Remoting配置文件的用法 2004-11-29 10:09 Casablanca
按照您的提示,我在IIS上配置多个Remote Object的时候没有添加端口,不同的Client端使用不同的 http://localhost/AppName/EndPoint.soap连接,失败了,我想端口和EndPoint是一一对应的,不过,现在就按照你的理解,如果配置的每个服务器都是由IIS分配端口的话,假如IIS可以控制不同服务对应的端口,可是假如我想自己指定端口的话,怎么做?很抱歉,我的问题很多:)   回复
  

#  re: .Net Remoting配置文件的用法 2004-11-29 11:21 Rickie
TO Casablanca:

上面关于IIS承载多个不同的Remote Objects,配置文件的用法是没有问题的,实际的项目就是这样配置的。
http://localhost/AppName/EndPoint.soap?wsdl
通过访问上面的URL来验证Remote Objects是否配置成功。
失败的原因很多:(1)Remote Objects本身存在问题;(2)配置文件存在问题等等。需要具体情况具体分析。
***
同一个Web Site不可以设置不同的port,因此不同服务Remote Objects在同一Web Site必须使用相同的端口。

你可以在IIS中创建多个Web Site,并指定不同的port,就可以实现你的要求了。   回复
  

#  re: .Net Remoting配置文件的用法 2004-12-01 15:12 render
按你文章第2部分来配置客户端时,如果remoting object是Singleton
的话,好象即使把obj的dll的copy到了客户端也不能用new来产生,只能用Activator.GetObject。是不是只有client actived的object才能用new 来产生proxy的?   回复
  

#  re: .Net Remoting配置文件的用法 2004-12-02 00:44 Rickie
To render,
Q: 如果remoting object是Singleton 的话,好象即使把obj的dll的copy到了客户端也不能用new来产生,只能用Activator.GetObject。
A: Client可以使用new来创建Remote Objects实例,注意需要在项目中引用该DLL,并且添加相应的namespace.

Q: 是不是只有client actived的object才能用new 来产生proxy的?
A: 不是,CAO and SAO都可以.   回复
  

#  re: .Net Remoting配置文件的用法 2004-12-07 11:34 render
谢谢rickie.
确实可以,是我自己不够小心。   回复
  

#  re: .Net Remoting配置文件的用法 2005-07-29 14:26 jxnetinfo
在服务器的Config文件能不能指定公网对外IP呢,如果不指定外网IP,在外网客户端好象不能访问   回复
  

#  re: .Net Remoting配置文件的用法 2005-08-05 08:03 建平
rickie:
可否請教您一個問題﹕
我在用.Net Remoting配置文件的時候老是出現如下錯誤﹐請問是什么問題﹐謝謝﹕
類型 'System.Runtime.Remoting.RemotingException' 的未處理例外狀況發生於 mscorlib.dll

其他資訊: 遠端組態已經失敗,發生例外狀況 System.IO.FileNotFoundException: 找不到檔案或組件名稱 'System.Runtime.Remoting' 或其相依性的其中之一。
檔案名稱: "System.Runtime.Remoting"
at System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Boolean isStringized, Evidence assemblySecurity, Boolean throwOnFileNotFound, Assembly locationHint, StackCrawlMark& stackMark)
at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Boolean stringized, Evidence assemblySecurity, StackCrawlMark& stackMark)
at System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark)
at System.Reflection.Assembly.Load(String assemblyString)
at System.Runtime.Remoting.RemotingConfigInfo.LoadType(String typeName, String assemblyName)
at System.Runtime.Remoting.RemotingConfigHandler.CreateChannelFromConfigEntry(ChannelEntry entry)
at System.Runtime.Remoting.RemotingConfigHandler.ConfigureChannels(RemotingXmlConfigFileData configData)
at System.Runtime.Remoting.RemotingConfigHandler.ConfigureRemoting(RemotingXmlConfigFileData configData)

=== Pre-bind state information ===
LOG: DisplayName = System.Runtime.Remoting
(Partial)
LOG: Appbase = K:/WebSite/Callback/Server/bin/Debug/
LOG: Initial PrivatePath = NULL
Calling assembly : (Unknown).
===

LOG: Found application configuration file (K:/WebSite/Callback/Server/bin/Debug/Server.exe.config).
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Post-policy reference: System.Runtime.Remoting
LOG: Attempting download of new URL file:///K:/WebSite/Callback/Server/bin/Debug/System.Runtime.Remoting.DLL.
LOG: Attempting download of new URL file:///K:/WebSite/Callback/Server/bin/Debug/System.Runtime.Remoting/System.Runtime.Remoting.DLL.
LOG: Attempting download of new URL file:///K:/WebSite/Callback/Server/bin/Debug/System.Runtime.Remoting.EXE.
LOG: Attempting download of new URL file:///K:/WebSite/Callback/Server/bin/Debug/System.Runtime.Remoting/System.Runtime.Remoting.EXE.

我的server 端部分代碼﹕
class Server
{
static void Main(string[] args)
{

RemotingConfiguration.Configure("Server.exe.config");

Console.WriteLine("Hit to exit");
Console.ReadLine();

}
}
server 的xml配置文件內容(該文件與Server.exe在相同目錄﹐且文件名為﹕Server.exe.config)﹕
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.runtime.remoting>
<application name="Hello">

<service>
<wellknown mode="SingleCall" type="Wrox.ProfessionalCSharp.Hello, RemoteHello"
objectUri="Hi" />
</service>

<channels>
<channel type="System.Runtime.Remoting.Channels.Tcp.TcpChannel,
System.Runtime.Remoting" port="6791" />
<channel type="System.Runtime.Remoting.Channels.Http.HttpChannel,
System.Runtime.Remoting" port="6792" />
</channels>

</application>
</system.runtime.remoting>
</configuration>

才學不久﹐如果您有時間幫忙看看是什么問題。
   回复
  

#  re: .Net Remoting配置文件的用法 2005-08-05 09:46 建平
rickie:
我的例子是C#高級編程一書中的source code,
我將﹕
<channel type="System.Runtime.Remoting.Channels.Http.HttpChannel,
System.Runtime.Remoting" port="6792" />
</channels>

改成﹕
<channel ref="http" port="6792" />
</channels>
就可以了﹐該書中怎么會用上面那種寫法。
有那位用過上面那種寫法嗎?
   回复
  

#  re: .Net Remoting配置文件的用法 2005-11-01 22:54 ChinaKokMan
那里有 Template Workflow 下载   回复
  

#  re: .Net Remoting配置文件的用法 2005-12-22 19:01 Aaron China
貌似老大好久没有来了,我也有个很肤浅的问题请教哦。。。。
在ie中输入 http://localhost/SP/Coordinator.rem/RemoteActivationService.rem?wsdl
产生下面的代码。

System.Runtime.Remoting.RemotingException: .Config file D:/Visual Studio Projects/C#/SP/web.config can not be read successfully due to exception

System.Runtime.Remoting.RemotingException: Sink providers must have an element name of 'formatter' or 'provider'.
at System.Runtime.Remoting.Activation.RemotingXmlConfigFileParser.ReportError(String errorStr, RemotingXmlConfigFileData configData)
at System.Runtime.Remoting.Activation.RemotingXmlConfigFileParser.ProcessSinkProviderNode(ConfigNode node, RemotingXmlConfigFileData configData,

Boolean isTemplate, Boolean isServer)
at System.Runtime.Remoting.Activation.RemotingXmlConfigFileParser.ProcessSinkProviderNodes(ConfigNode node, ChannelEntry channelEntry,

RemotingXmlConfigFileData configData, Boolean isServer)
at System.Runtime.Remoting.Activation.RemotingXmlConfigFileParser.ProcessChannelsChannelNode(ConfigNode node, RemotingXmlConfigFileData

configData, Boolean isTemplate)
at System.Runtime.Remoting.Activation.RemotingXmlConfigFileParser.ProcessChannelsNode(ConfigNode node, RemotingXmlConfigFileData configData)
at System.Runtime.Remoting.Activation.RemotingXmlConfigFileParser.ProcessApplicationNode(ConfigNode node, RemotingXmlConfigFileData configData)
at System.Runtime.Remoting.Activation.RemotingXmlConfigFileParser.ParseConfigFile(String filename)
at System.Runtime.Remoting.RemotingConfigHandler.LoadConfigurationFromXmlFile(String filename).
at System.Runtime.Remoting.RemotingConfigHandler.LoadConfigurationFromXmlFile(String filename)
at System.Runtime.Remoting.RemotingConfiguration.Configure(String filename)
at System.Runtime.Remoting.Channels.Http.HttpRemotingHandler.InternalProcessRequest(HttpContext context)


而我的配置文件是这样的:SP/web.config

<?xml version="1.0" encoding="utf-8" ?>
- <configuration>
- <system.runtime.remoting>
- <application>
- <service>
<wellknown mode="Singleton" type="Coordinator,PaintCoordinator" objectUri="Coordinator.rem" />
</service>
- <channels>
- <channel ref="http">
- <serverProviders>
<provider ref="wsdl" />
<formatter ref="binary" typeFilterLevel="Full" />
</serverProviders>
- <clientProviders>
<formatter ref="binary" />
</clientProviders>
</channel>
</channels>
</application>
</system.runtime.remoting>
</configuration>

我的dll路径
SP/bin/PaintCoordinator.dll


如果我运行客户端的话就会提示说
BinaryFormatter Version incompatibility. Expected Version 1.0. Received Version 1835627630.1699884645.


到底是怎么回事呢,老大,帮忙指点指点啊~~~   回复
  

#  re: .Net Remoting配置文件的用法 2006-01-03 20:29 Aaron China
我知道了,原来
<provider ref="wsdl" />
<formatter ref="binary" typeFilterLevel="Full" />
这两行写反了....   回复
  

#  re: .Net Remoting配置文件的用法 2006-06-14 16:21 Ross
客户端激活的对象可不可以用IIS承载   回复 
 
#  re: .Net Remoting配置文件的用法 2004-11-04 10:40 Casablanca
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值