我开发了一个wcf服务。由于非.NET客户端也将调用它,所以我使用了basichttpbinding。有些方法需要模拟。这是通过用以下方式装饰webmethods来强制的:
[OperationBehavior(Impersonation = ImpersonationOption.Required)]在测试服务器上部署服务后,当我调用该服务时,会出现一个奇怪的错误:
无法加载文件或程序集“log4net、Version=1.2.10.0、Culture=neutral、PublicKeyToken=1b44e1d426115821”或其依赖项之一。没有提供所需的模拟级别,或者提供的模拟级别无效。(HRESULT例外: 0x80070542)
我得到这个错误独立于我调用服务的方式。我通过wcfTestClient调用它时得到它,当我通过我编写的控制台应用程序调用它时得到它。(我将webservice作为web引用添加到此应用程序中,以模拟非.net客户端的行为。)
有什么想法吗?
PS:这是我的webservice的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>发布于 2011-07-13 10:52:39
在WCF中,客户端必须显式地允许模拟。在WCF客户端中,可以通过配置向客户端代理添加行为:
<behaviors>
<endpointBehaviors>
<behavior name="myBehavior">
<clientCredentials>
<windows allowedImpersonationLevel="Impersonation" />
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>或在守则中:
proxy.ClientCredentials.Windows.AllowImpersonationLevel = TokenImpersonationLevel.Impersonation;我希望这必须配置为WcfTestClient,因为默认的模拟级别只允许idnetification。
如果使用ASMX代理,请确保您是通过你的证书。
我的观点是,对于非.NET客户端使用的服务来说,windows身份验证不是一个好选择(特别是如果您也是指非Windows)。
发布于 2011-07-13 10:02:02
看起来,log4net库与这个模拟级别是无法兼容的。如果您删除引用,它将工作。
https://stackoverflow.com/questions/6676938
复制相似问题