DCOM简单示例(05)

本篇文章介绍了如何写一个简单的DCOM客户端(CSharp)。

1、首先要导入COM组件编译时生成的TBL文件,ATLService.tlb

2、然后用下面的代码就可以调用了,好简单哦

using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using ATLServiceLib;

namespace CSTest
{
    class Program
    {
        static void Main(string[] args)
        {
            Type justATestType = System.Type.GetTypeFromProgID("ATLService.JustATestSvc","172.16.172.3");
            IJustATestSvc svc = (IJustATestSvc)System.Activator.CreateInstance(justATestType);
            int c = svc.Add(1, 2);
            System.Console.WriteLine(c);
            String retValue = svc.SayHiTo("dcom");
            System.Console.WriteLine(retValue);
            System.Console.Read();
        }
    }
}

Comments are closed.