我想访问远程服务器上的分区COM +应用程序。 我已经试过这样:在C#中使用分区的远程服务器上的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)}"
我的问题是非常simular这样: COM+ object activation in a different partition
您确定这不是由设计?该错误消息似乎与您的设置一致。我应该联系微软。还请检查:https://social.technet.microsoft.com/Forums/windows/en-US/a601d45a-10c0-4da9-a424-d35afef22161/how-to-enable-windows-7-windows-8-com-分区功能 –
我想你不知何故必须将服务器名称合并到名称中。现在您只能使用服务器名称连接到服务器上的目录。您不使用它来创建对象,就像在不使用分区的情况下一样。所以你实际上试图在你没有启用分区的本地机器上创建对象。该解决方案可能不会像@SimonMourier所提供的链接所建议的那样在本地启用分区,因为这只允许您在本地创建对象,而这可能不是您想要的。 –
@MikaelEriksson理论上也许是可能的。实际上看起来像现在可能不被支持。 BindToMoniker通过调用CreateBindCtx(获取IBindCtx),MkParseDisplayName以及最后一个BindMoniker来实现。您可以自己实现序列,而不是使用默认的BindCtx(具有BIND_OPTS结构),您可以使用BIND_OPTS2结构自己创建一个序列。它有一个带有服务器信息的pServerInfo。现在这是好的一部分。来自文档的不好的部分:类名字对象目前没有兑现pServerInfo标志。所以这听起来像现在不能工作。 – Uwe