我想訪問遠程服務器上的分區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