【发布时间】:2017-05-17 10:37:05
【问题描述】:
我想访问远程服务器上的分区 COM+ 应用程序。 我试过这个:
using COMAdmin
using System.Runtime.InteropServices;
_serverName = myRemoteServer;
_partionName = myPartionName;
_message = myMessage;
ICOMAdminCatalog2 catalog = new COMAdminCatalog();
catalog.Connect(_serverName);
string moniker = string.Empty;
string MsgInClassId = "E3BD1489-30DD-4380-856A-12B959502BFD";
//we are using partitions
if (!string.IsNullOrEmpty(_partitionName))
{
COMAdminCatalogCollection partitions = catalog.GetCollection("Partitions");
partitions.Populate();
string partitionId = string.Empty;
foreach (ICatalogObject item in partitions)
{
if (item.Name == _partitionName)
{
partitionId = item.Key;
break;
}
}
if (!string.IsNullOrEmpty(partitionId) )
{
moniker = $"partition:{partitionId}/new:{new Guid(MsgInClassId)}";
try
{
var M = (IMsgInManager)Marshal.BindToMoniker(moniker);
M.AddMsg(_message);
}
catch (Exception ex)
{
throw new Exception($"We can not use: {_partitionName} with Id {partitionId}. {ex.ToString()}");
}
}
else
{
throw;
}
}
else
//we don't have partitions and this will work
{
Type T = Type.GetTypeFromCLSID(new Guid(MsgInClassId), _serverName, true);
var M = (IMsgInManager)Activator.CreateInstance(T);
M.AddMsg(_message);
}
}
因此,当我们在(远程)机器上本地时,分区正在使用名字对象和 Marshal.BindToMoniker。 但是当我尝试从我的机器远程执行相同操作时,我收到一个错误 Marshal.BindToMoniker 表示 Partitons 未启用。因为在我的机器上没有启用分区。
Message = "COM+ partitions are currently disabled. (Exception from HRESULT: 0x80110824)"
如何使用 Marshal.BindToMoniker 在远程服务器上运行。 我可以添加到名字字符串中吗,即
moniker = $"server:_server/partition:{partitionId}/new:{new Guid(MsgInClassId)}"
我的问题与此非常相似: COM+ object activation in a different partition
【问题讨论】:
-
你确定这不是设计的吗?错误消息似乎与您的设置一致。我猜你应该联系微软。还要检查这个:social.technet.microsoft.com/Forums/windows/en-US/…
-
我猜你必须以某种方式将服务器名称合并到名字对象中。现在您只使用服务器名称连接到服务器上的目录。您不会像在不使用分区的情况下那样使用它来创建对象。因此,您实际上是在尝试在未启用分区的本地计算机上创建对象。解决方案可能不是按照@SimonMourier 提供的链接所建议的那样在本地启用分区,因为这只会允许您在本地创建对象,而这可能不是您想要的。
-
@MikaelEriksson 理论上是可能的。实际上看起来目前可能不支持。 BindToMoniker 是通过调用 CreateBindCtx(获取 IBindCtx)、MkParseDisplayName 和最后一个 BindMoniker 来实现的。您可以自己实现序列,而不是使用默认的 BindCtx(具有 BIND_OPTS 结构),您可以使用 BIND_OPTS2 结构自己创建一个。那有一个带有服务器信息的 pServerInfo。现在这是好的部分。文档中的坏处:类名字对象当前不支持 pServerInfo 标志。所以听起来它现在不起作用。
-
在排队的组件中有一个“ComputerName=cc/new:”。您可以尝试“ComputerName:”只是为了它。但这更像是抓住稻草;-)。
-
@MikaelEriksson 是的,这就是我的意思。然后我会写一些详细信息和链接以获得答案。
标签: c# remote-server com+ activation moniker