gpt4 book ai didi

.net - 为什么当我在 WCF 服务中模拟时,当我尝试运行 LINQ to SQL 查询时,我的服务无法加载 System.Transactions?

转载 作者:行者123 更新时间:2023-12-02 12:36:07 25 4
gpt4 key购买 nike

我有一个 WCF 服务,托管在 IIS 7.0 中,需要运行数据库查询。为了获得执行此操作的正确权限,我在服务中模拟如下:

代码

[OperationBehavior(Impersonation = ImpersonationOption.Allowed)]
public void MyOperation(int arg)

配置

<behavior name="ReceivingServiceBehavior">
<!-- Other behaviors -->
<serviceAuthorization impersonateCallerForAllOperations="true" />
</behavior>

当我尝试连接并运行查询时,我得到以下信息:

Exception - System.IO.FileLoadException: Could not load file orassembly 'System.Transactions, Version=2.0.0.0, Culture=neutral,PublicKeyToken=b77a5c561934e089' or one of its dependencies. Either arequired impersonation level was not provided, or the providedimpersonation level is invalid. (Exception from HRESULT: 0x80070542)File name: 'System.Transactions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' ---> System.Runtime.InteropServices.COMException (0x80070542): Either a required impersonation level was not provided, or the provided impersonation level is invalid. (Exception from HRESULT: 0x80070542)   at System.Data.Linq.SqlClient.SqlConnectionManager.UseConnection(IConnectionUser user)   at System.Data.Linq.SqlClient.SqlProvider.get_IsSqlCe()   at System.Data.Linq.SqlClient.SqlProvider.InitializeProviderMode()   at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query)   at System.Data.Linq.DataQuery`1.System.Collections.Generic.IEnumerable.GetEnumerator()   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)   at Fourth.GHS.MessageRelay.RegistrationDBStorage.FindRegistration(SystemKey key)

最佳答案

您的 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>

如果没有明确指定,则默认设置为识别。查看this blog post了解更多信息。

关于.net - 为什么当我在 WCF 服务中模拟时,当我尝试运行 LINQ to SQL 查询时,我的服务无法加载 System.Transactions?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/277881/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com