COM+伺服器的.Net組件實現 – 伺服器端

來源:互聯網
上載者:User
閑來無事,用C#控制項(Class Library)作個了簡單的雙機互連COM+樣本

1. 準備工作:兩台主機,各自軟體配置分別為

1. 伺服器:Vs.net 2003 + .Net Framework 1.1 SDK SP1 + WinXP pro SP2

1. 用戶端:.Net Framework 1.1 SP1 Distributed Package + WinXP pro SP2

2. 在伺服器上建立一個C# Class Library工程,將System.EnterpriseServices.dll添加進項目引用

3. 開啟Vs.net 2003命令提示控制台,在%Project Directory%目錄下產生一個用於組件簽名的金鑰組,輸入

3. sn -k keyfile.snk

4. 修改項目的AssemblyInfo.cs檔案,在其中添加引用聲明:
using System.EnterpriseServices;

4. 同時修改/添加其中幾行Assembly定義屬性:
[assembly: AssemblyDelaySign(false)]

[assembly: AssemblyKeyFile("..\\..\\keyfile.snk")]

[assembly: AssemblyKeyName("")]


[assembly: ApplicationActivation(ActivationOption.Server)]

[assembly: ApplicationAccessControl(false)]

5. 修改項目Class1.cs檔案,添加COM+伺服器組件的主體內容如下:
using System;

using System.EnterpriseServices;


namespace ccc

{

    public interface IMathEx

    {

        int sum(int a,int b);

    }

    public class Test: ServicedComponent,IMathEx

    {

        public Test()

        {

        }


        IMathEx 成員#region IMathEx 成員

        public int sum(int a,int b)

        {

            return a+b;

        }

        #endregion

    }

}

5. 其中,我們在組件名空間ccc中定義了一個IMathEx介面,裡面只有一個求和函數,而類Test實現了這個介面

6. 編譯工程項目,%Project Directory%\bin\debug目錄下將產生ccc.dll和ccc.tlb兩個檔案

7. 在%Project Directory%\bin\debug目錄下手工註冊Assembly至COM+目錄,鍵入命令:

7. regsvcs -appname:MyApp ccc.dll

8. 至此伺服器端組件開發、部署完畢

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.