非淡泊无以明志,非宁静无以致远 -心静如止水,动于静

Remoting experienes

在做Remoting的時候,寫的代碼在第一次運行的時候還是正常,但再次執行的時候,發現有類似"http already registed ...."的錯誤,顯然是因為在客戶端不能重復注冊同一個channel, 后來加一個ChannelServices.RegisteredChannels.Length判斷是否有channel注冊就可以正常工作了

不work的代碼:
    public sealed class RemotingDataService : DataService
    {
        public RemotingDataService()
        {
               RemotingConfiguration.Configure("ClientRemoting.config", false); // false means we needn't do security check currently
        }
... ...

Work的代碼:
    public sealed class RemotingDataService : DataService
    {
        public RemotingDataService()
        {
            if (ChannelServices.RegisteredChannels.Length == 0)
                RemotingConfiguration.Configure("ClientRemoting.config", false); // false means we needn't do security check currently
        }

補充:
當在同一台機器是可以用上述方法順利調用remoting的,但是當把remoting service以IIS host的方式發布到另外一台機器的時候,經常出現 **** (403) Forbidden的錯誤。經過長時間的查找,原來是在網絡上調用IIS Host的remoting需要身份, Remoting本身并不具務權限的機制,因為它被host在IIS中,所以必須經過IIS那道關卡,解決方法是
1. 在IIS管理器將remoting站點的匿名訪問不選,只選integrate with Windows, And choice correct Dot net framework version. And let this Web site has script only permission, because it is web application site.
2. 在IIS主機中創建一個Windows帳號,可以只為一般用戶權限就可
3. 修改客戶端調用remoting service代碼,加入此帳號即可
.... ....
                IRemotingDataService service = (IRemotingDataService)Activator.GetObject(typeof(DDNP.Layers.DSL.IRemotingDataService), myEntries[0].ObjectUrl);
                IDictionary Props = ChannelServices.GetChannelSinkProperties(service);
                Props["credentials"] = new NetworkCredential(ConfigurationManager.AppSettings["remotingusername"], ConfigurationManager.AppSettings["remotinguserpwd"]);

.... ....


Today, I tried to setup multiple remoting services that was host in a physical machine. At client, can config multiple Welknow service to connect these 2 service :
<configuration>
 <system.runtime.remoting>
  <application>
   <client displayName="DDNP Remoting">
    <wellknown
       type="DDNP.Layers.DSL.RemotingDataServiceProxy, DDNP.Layers.DSL"
       url="http://localhost:8085/DBDataService2.rem"/>  <!-- If remoting object reside in IIS, you should use: http://localhost:port/DBDataService2.rem-->
    <wellknown
       type="DDNP.Layers.DSL.RemotingDataServiceProxy1, DDNP.Layers.DSL"
       url="http://localhost:8086/DBDataService2.rem"/>
    <!-- If remoting object reside in IIS, you should use: http://localhost:port/DBDataService2.rem-->
   </client>
   <channels>
    <channel
       ref="http"
       port="0"/>
    
    <channel
       ref="tcp"
       port="0"/>
   </channels>
  </application>
 </system.runtime.remoting>
</configuration>
posted @ 2007-08-03 09:28  烟雨客  阅读(246)  评论(0编辑  收藏  举报