我想從我的代碼('IntPub')中調用Apache ActiveMQ NMS版本1.6.0,該代碼必須在.NET 4.0環境的沙箱中運行,出於安全原因。創建沙盒的程序使我的代碼「部分可信」,因此「安全透明」,這似乎意味着它不能創建ConnectionFactory(請參閱下面的錯誤日誌),因爲NMS似乎是'安全關鍵'。下面是導致此錯誤代碼:如何從沙箱中調用Apache NMS?
connecturi = new Uri("tcp://my.server.com:61616");
var connectionFactory = new ConnectionFactory(connecturi);
我也試圖與替代類似的結果:
connecturi = new Uri("activemq:tcp://my.server.com:61616");
var connectionFactory = NMSConnectionFactory.CreateConnectionFactory(connecturi);
既然我不能改變我的程序集的安全級別(沙箱阻止它)是有一種方法可以使NMS運行爲「安全關鍵」,因此可以通過「安全透明」代碼調用它?我是否必須重新編譯它才能這樣做,還是NMS做了一些永遠不會被認爲是「安全關鍵」的操作?
我明白任何幫助或建議......
Assembly 'IntPub, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6fa620743b8dc60a' is partially trusted, which causes the CLR to make it entirely security transparent regardless of any transparency annotations in the assembly itself. In order to access security critical code, this assembly must be fully trusted.Detail:
<OrganizationServiceFault xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/xrm/2011/Contracts">
<ErrorCode>-2147220956</ErrorCode>
<ErrorDetails xmlns:d2p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic" />
<Message>Unexpected exception from plug-in (Execute): Test.Client: System.MethodAccessException: Attempt by security transparent method 'Test.Client.Execute(System.IServiceProvider)' to access security critical method 'Apache.NMS.ActiveMQ.ConnectionFactory..ctor(System.Uri)' failed.
謝謝,約翰。您對此限制是正確的,但不幸的是,CRM Online無法更改。所以它引出了一個問題:「有沒有辦法讓NMS通過http:?與ActiveMQ進行通信?」此外,還要回答這個問題:「NMS還有什麼會違反安全模型嗎?」 – PrgTrdr
如果你的目標客戶關係管理在線,你可能會有更好的運氣在Azure(或其他地方)託管一個web服務來完成你所需要的工作,並從你的插件中調用該web服務。雖然有延遲成本,但要小心 - 尤其是因爲插件在CRM殺死它們之前可以運行的最長時間。 –