使.NET COM对象可通过LAN访问? [英] Make .NET COM object accessable over the LAN?

查看:76
本文介绍了使.NET COM对象可通过LAN访问?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我使用C#创建了COM对象:

Hello, I've created COM-object using C#:

using System.Runtime.InteropServices;
using System.Diagnostics;
using System;

[ComVisible(true)]
[Guid("<interface_guid>")]
public interface IMyTest {
    string Test();
}

[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
[Guid("<class_guid>")]
public class MyTest : IMyTest {
    public string Test() {
        var pro = Process.GetCurrentProcess();
        var mac = Environment.MachineName;

        return $"{mac} - {pro.Id} - {pro.ProcessName}";
    }
}

我正在以这样编程方式注册COM-object:

I'm registering COM-object programatically like this:

var asm = Assembly.LoadFrom("<path_to_the_dll>");
var reg = new RegistrationServices();

reg.RegisterAssembly(asm, AssemblyRegistrationFlags.SetCodeBase);

var nam = "AppID\\<class_guid>";
using(var key = Registry.ClassesRoot.CreateSubkey(nam)) {
    key.SetValue("DllSurrogate", "", RegistryValueKind.String);
    key.SetValue("", "MyTest", RegistryValueKind.String);
}

nam = "CLSID\\<class_guid>";
using(var key = Registry.ClassesRoot.CreateSubkey(nam)) {
    key.SetValue("AppID", "<class_guid>", RegistryValueKind.String);
}

当我尝试使用VBScript访问本地计算机上的对象时,一切正常

When I try to access the object on local machine with VBScript, everything works

set obj = CreateObject("MyTest", "localhost")    ' Works
set obj = CreateObject("MyTest", "127.0.0.1")    ' Works
set obj = CreateObject("MyTest", "<ip_address>") ' Works

WScript.Echo(obj.Test)

但是,当我尝试从远程机器访问它时,我得到HRESULT为0x800A01AD的错误。

However, when I try accessing it from remote machine, I get error with HRESULT of 0x800A01AD.

你能告诉我这里我做错了吗?

Can you please tell me what I'm doing wrong here?

推荐答案

嗨Leff lvanov,

Hi Leff lvanov,

欢迎来到MSDN论坛。

Welcome to MSDN forum.

对于你的问题,请重写你的Com对象通过创建Com +应用程序。然后你可以远程访问Com +应用程序。

For your question, please rewrite your Com object by creating Com+ application. And then you could access the Com+ application remotely.

请检查代码示例,了解如何创建Com +应用程序。

Please check the code sample about how to create a Com+ application.

https://code.msdn.microsoft.com/windowsdesktop/Creating-a-COM-Component-7ffbab9b

您可以查看有关如何访问Com +应用程序的代码项目示例。

You could check the example of code project about how to access Com+ application.

https://stackoverflow.com/questions/1597060/calling-a-com-component-remotely-using-c-sharp

最诚挚的问候,

Wendy


这篇关于使.NET COM对象可通过LAN访问?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆