我想访问远程服务器上的分区 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