gpt4 book ai didi

wcf - 调用 wcf-service 时出现模拟错误

转载 作者:行者123 更新时间:2023-12-01 07:57:06 24 4
gpt4 key购买 nike

我开发了一个 wcf 服务。因为它也会被非 .net 客户端调用,所以我使用了 basichttpbinding。有些方法需要模拟。这是通过装饰 web 方法强制执行的:

 [OperationBehavior(Impersonation = ImpersonationOption.Required)]

在我们的测试服务器上部署服务后,调用服务时出现奇怪的错误:

Could not load file or assembly 'log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821' or one of its dependencies. Either a required impersonation level was not provided, or the provided impersonation level is invalid. (Exception from HRESULT: 0x80070542)

无论调用服务的方式如何,我都会收到此错误。当我通过 wcfTestClient 调用它时我得到它,当我通过我编写的控制台应用程序调用它时我得到它。 (我将 web 服务添加为该应用程序的 web 引用,以模拟非 .net 客户端的行为。)

有什么想法吗?


PS:这是我的网络服务的 web.config:

  <system.web>
<compilation targetFramework="4.0" />
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding closeTimeout="00:15:00" openTimeout="00:15:00" sendTimeout="00:15:00" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="">
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<defaultDocument>
<files>
<add value="CrmConnectorDiamondData.svc" />
</files>
</defaultDocument>
</system.webServer>
</configuration>

最佳答案

在 WCF 客户端中,客户端必须明确允许模拟。在 WCF 客户端中,它是通过配置向客户端代理添加行为来完成的:

<behaviors>
<endpointBehaviors>
<behavior name="myBehavior">
<clientCredentials>
<windows allowedImpersonationLevel="Impersonation" />
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>

或者在代码中:

proxy.ClientCredentials.Windows.AllowImpersonationLevel = TokenImpersonationLevel.Impersonation;

我希望这必须为 WcfTestClient 配置,因为默认模拟级别只允许 idnetification。

如果是 ASMX 代理,请确保您是 passing your credentials .

我的观点是,Windows 身份验证对于非 .NET 客户端(特别是如果您也指非 Windows)使用的服务不是一个好的选择。

关于wcf - 调用 wcf-service 时出现模拟错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6676938/

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