Dot-Net
為什麼,當我在 WCF 服務中模擬時,當我嘗試執行 LINQ to SQL 查詢時,我的服務不能載入 System.Transactions?
我有一個 WCF 服務,託管在 IIS 7.0 中,需要執行數據庫查詢。為了獲得執行此操作的正確權限,我在服務中模擬如下:
程式碼
[OperationBehavior(Impersonation = ImpersonationOption.Allowed)] public void MyOperation(int arg)配置
<behavior name="ReceivingServiceBehavior"> <!-- Other behaviors --> <serviceAuthorization impersonateCallerForAllOperations="true" /> </behavior>當我嘗試連接並執行我的查詢時,我得到以下資訊:
異常 - System.IO.FileLoadException:無法載入文件或 程序集'System.Transactions,版本=2.0.0.0,文化=中性, PublicKeyToken=b77a5c561934e089' 或其依賴項之一。要麼 未提供所需的模擬級別,或提供的 模擬級別無效。(來自 HRESULT 的異常:0x80070542) 文件名:'System.Transactions,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089' ---> System.Runtime.InteropServices.COMException (0x80070542):未提供所需的模擬級別,或提供的模擬級別無效。(來自 HRESULT 的異常:0x80070542) 在 System.Data.Linq.SqlClient.SqlConnectionManager.UseConnection(IConnectionUser 使用者) 在 System.Data.Linq.SqlClient.SqlProvider.get_IsSqlCe() 在 System.Data.Linq.SqlClient.SqlProvider.InitializeProviderMode() 在 System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(表達式查詢) 在 System.Data.Linq.DataQuery`1.System.Collections.Generic.IEnumerable.GetEnumerator() 在 System.Linq.Buffer`1..ctor(IEnumerable`1 源) 在 System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 源) 在 Fourth.GHS.MessageRelay.RegistrationDBStorage.FindRegistration(SystemKey 鍵)
如果您希望 SQL 查詢作為模擬身份執行,您實際上可能需要啟用對 SQL 伺服器的委派。查看這篇文章了解更多資訊:
您的 WCF 客戶端是否設置了所需的“允許的模擬級別”:
<?xml version="1.0" encoding="utf-8" ?> <configuration> <system.serviceModel> <!-- .... --> <behaviors> <endpointBehaviors> <behavior name="ImpersonationBehavior"> <clientCredentials> <windows allowedImpersonationLevel="Impersonation" /> </clientCredentials> </behavior> </endpointBehaviors> </behaviors> </system.serviceModel> </configuration>預設情況下,如果沒有明確指定,則將其設置為**標識。**查看此部落格文章了解更多資訊。