内射老阿姨1区2区3区4区_久久精品人人做人人爽电影蜜月_久久国产精品亚洲77777_99精品又大又爽又粗少妇毛片

Castle整合.NETRemoting-創(chuàng)新互聯(lián)

今天研究了一下Castle的Remoting Facility.記錄如下:

在萬年等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供網(wǎng)站設(shè)計制作、網(wǎng)站設(shè)計 網(wǎng)站設(shè)計制作按需定制網(wǎng)站,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),品牌網(wǎng)站設(shè)計,營銷型網(wǎng)站建設(shè),成都外貿(mào)網(wǎng)站制作,萬年網(wǎng)站建設(shè)費用合理。

微軟以前使用COM/DCOM的技術(shù)來處理分布式系統(tǒng)架構(gòu),通過Client端的Proxy代理程序來呼叫遠程Server機器上的對象。.NET Framework則使用.NET Remoting或Web Services技術(shù)來實作分布式處理的工作概念;在這里針對.NET Remoting的設(shè)計架構(gòu)做一個初步的簡介和Castle整合示例。

.NET Framework提供了多種的機制來支持Remoting,如:

.利用Channel來負責(zé)信息的發(fā)送與接收。
.利用Formatter來負責(zé)在信息要通過channel發(fā)送出去之前,先將信息做適當(dāng)?shù)募用?,或于信息在通過Channel接收進來之后,先將信息做相對的解密工作。
.利用Proxy來呼叫遠程的對象執(zhí)行所要的功能呼叫。

其關(guān)系如下圖所示:

Castle 整合.NET Remoting
Channel 和 Formatter

在遠程對象被使用之前,必須先在Server端注冊好信息發(fā)送的信道(Channel),這些Channel可通過.NET Remotin configuration file或 ChannelServices對象類別的RegisterChannel方法來注冊。

在Channel的使用上,.NET Framework支持HTTP、TCP及SMTP等通道。若使用HTTP Channel ,則使用SOAP協(xié)議來收送信息,所有的信息會被發(fā)送到SOAP Formatter中,被序列化(serialized)成XML的格式,而SOAP所需的headers也會被加入。至于使用TCP Channel者,則使用TCP協(xié)議來將信息發(fā)送到Binary Formatter中,以Binary Stream的方式來將信息發(fā)送到URI目的地。(URI : Universal Resource Identifier,類似大家所熟悉的URL)。

Activation and Proxy
Server-Side Activation
Server端在Client端要獲取Remoting對象時必需在Server端能自動啟動Remoting對象,可使用RemotingConfiguration對象類別的RegisterWellKnownServiceType方法來完成這項工作。

Client-Side Activation
Client端要使用遠程對象之前,可使用New 或Activator 對象類別所提供的CreateInstance或GetObject方法來啟動對象并傳回Proxy,以便Client端可通過Proxy來執(zhí)行叫用遠程對象的方法。

范例
以下分三個步驟來介紹

1.    建立Remoting對象

2.    在Server上初始Remoting物件

3.    Client端使用Remoting對象

步驟1:建立Remoting對象
建立一個MathServer對象類別,提供Sum方法,可給予一連串的整數(shù)由Sum方法代為計算總和。程序代碼如下,并說明于后:

using System;

namespace RemoteSample.Components

{

    /// <summary>

    /// Class1 的摘要說明。

    /// </summary>

    public interface IRemoteMath

    {

        int Sum(params int[] a);

        int CallCounter

        {

             get;

        }

    }

}

using System;

using RemoteSample.Components;

namespace RemoteSample.Components

{

    /// <summary>

    /// RemoteMath 的摘要說明。

    /// </summary>

    public class RemoteMath: MarshalByRefObject,IRemoteMath

    {

        private int callCounter = 0;

        public RemoteMath()

        {

  

        }

        #region 接口IRemoteMath的成員實現(xiàn)

        /// <summary>

        /// 求和計算

        /// </summary>

        /// <param name="a"></param>

        /// <returns></returns>

        public int Sum(params int[] a)

        {

             int sum = 0;

             for (int i = 0; i <= a.Length - 1; i++)

             {

                  sum += a[i];

             }

             callCounter += 1;

             return sum;

        }

        public int CallCounter

        {

             get

             {

                  return this.callCounter;

             }

        }

        #endregion

    }

}

說明:Remoting對象必須繼承自MarshalByRefObject,這樣才能通過網(wǎng)絡(luò),將對象執(zhí)行個體的參考位置傳遞給呼叫端。

步驟2:在Server上初始化Remoting對象,程序代碼如下,并說明于后:

namespace RemoteSample.Server

{

    class RemoteServerMain

    {

        [STAThread]

        internal static void Main(string[] args)

        {

             IWindsorContainer container = new RemotingContainer();

             Console.ReadLine();

        }

    }

}

ServerConfig.xml文件:

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

<configuration>

    <facilities>

        <facility id="remote.facility" type="Castle.Facilities.Remoting.RemotingFacility, Castle.Facilities.Remoting"

                  remotingConfigurationFile ="../../RemotingTcpConfig.config"

               isServer="true"

                registryUri="kernel.rem" >

        </facility>

    </facilities>

    <components>

        <component

             id="remote.math"

             service="RemoteSample.Components.IRemoteMath, RemoteSample.Components"

             type="RemoteSample.Components.RemoteMath, RemoteSample.Components"

             remoteserver="component"  >

        </component>

    </components>

</configuration>

RemotingTcpConfig.config文件:

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

<configuration>

   <system.runtime.remoting>

      <application>

          <channels>

             <channel ref="tcp" port="2133" />

          </channels>

      </application>

   </system.runtime.remoting>

</configuration>

說明:

使用Castle 的Remoting Facillity 使用Remoting 。

1.配置指出在2133 port上要建立TCP Channel, 2133 port上要建立tcp Channel

2.<components>指出在Server端注冊所要使用的組件、服務(wù)的名稱及啟動的方式。其中component表示一個執(zhí)行個體可供多個前端來呼叫,可保留其狀態(tài),另一種則為ClientActivated,一個執(zhí)行個體只能服務(wù)一個前端的呼叫,無法保留其狀態(tài)。

步驟3:在Client端使用Remoting對象

ClientConfig.xml

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

<configuration>

    <facilities>

        <facility

                  id="remote.facility"

                type="Castle.Facilities.Remoting.RemotingFacility, Castle.Facilities.Remoting"

                remotingConfigurationFile="../../RemotingTcpConfigClient.config"

                isClient="true"

                remoteKernelUri="tcp://localhost:2133/kernel.rem"

                baseUri="tcp://localhost:2133" >

        </facility>

    </facilities>

 <components>

   <component

        id="remote.math"

        service="RemoteSample.Components.IRemoteMath, RemoteSample.Components"

        type="RemoteSample.Components.RemoteMath, RemoteSample.Components"

        remoteclient="component" />

 </components>

</configuration>

RemotingTcpConfigClient.config

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

<configuration>

    <system.runtime.remoting>

        <application>

             <channels>

                  <channel ref="tcp" port="0" />

             </channels>

        </application>

    </system.runtime.remoting>

</configuration>

程序代碼如下:

namespace RemoteSample.Client

{

    /// <summary>

    /// RemoteClient的摘要說明。

    /// </summary>

    public class RemoteClientMain

    {

        [STAThread]

        static void Main(String[] args)

        {

             IWindsorContainer container = new RemotingContainer();

             IRemoteMath remoteMath = (IRemoteMath)container[typeof(IRemoteMath)] ;

             Console.WriteLine("Client1 TCP Call Sum method {0} Counter {1}",remoteMath.Sum(10, 20, 30),remoteMath.CallCounter);

             Console.WriteLine("....press a key to stop");

             Console.ReadLine();

        }

    }

}

新航道雅思

創(chuàng)新互聯(lián)www.cdcxhl.cn,專業(yè)提供香港、美國云服務(wù)器,動態(tài)BGP最優(yōu)骨干路由自動選擇,持續(xù)穩(wěn)定高效的網(wǎng)絡(luò)助力業(yè)務(wù)部署。公司持有工信部辦法的idc、isp許可證, 機房獨有T級流量清洗系統(tǒng)配攻擊溯源,準確進行流量調(diào)度,確保服務(wù)器高可用性。佳節(jié)活動現(xiàn)已開啟,新人活動云服務(wù)器買多久送多久。

本文名稱:Castle整合.NETRemoting-創(chuàng)新互聯(lián)
網(wǎng)頁URL:http://www.rwnh.cn/article2/jdsoc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供小程序開發(fā)移動網(wǎng)站建設(shè)、品牌網(wǎng)站建設(shè)、網(wǎng)站收錄、微信公眾號、用戶體驗

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站建設(shè)
泸州市| 偏关县| 江川县| 稻城县| 宜宾县| 灌云县| 田林县| 上高县| 眉山市| 左权县| 新昌县| 尉氏县| 万宁市| 上思县| 乳源| 建阳市| 璧山县| 赤城县| 夏河县| 万全县| 扬州市| 长沙市| 崇信县| 台山市| 西乌| 调兵山市| 大冶市| 侯马市| 福鼎市| 太仓市| 康定县| 土默特左旗| 永济市| 韶关市| 竹溪县| 花莲县| 晋州市| 怀安县| 游戏| 德庆县| 黄浦区|