首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >调用wcf-service时的模拟错误

调用wcf-service时的模拟错误
EN

Stack Overflow用户
提问于 2011-07-13 09:40:29
回答 2查看 5.8K关注 0票数 3

我开发了一个wcf服务。由于非.NET客户端也将调用它,所以我使用了basichttpbinding。有些方法需要模拟。这是通过用以下方式装饰webmethods来强制的:

代码语言:javascript
运行
复制
 [OperationBehavior(Impersonation = ImpersonationOption.Required)]

在测试服务器上部署服务后,当我调用该服务时,会出现一个奇怪的错误:

无法加载文件或程序集“log4net、Version=1.2.10.0、Culture=neutral、PublicKeyToken=1b44e1d426115821”或其依赖项之一。没有提供所需的模拟级别,或者提供的模拟级别无效。(HRESULT例外: 0x80070542)

我得到这个错误独立于我调用服务的方式。我通过wcfTestClient调用它时得到它,当我通过我编写的控制台应用程序调用它时得到它。(我将webservice作为web引用添加到此应用程序中,以模拟非.net客户端的行为。)

有什么想法吗?

PS:这是我的webservice的web.config:

代码语言:javascript
运行
复制
  <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>
EN

回答 2

Stack Overflow用户

发布于 2011-07-13 10:52:39

在WCF中,客户端必须显式地允许模拟。在WCF客户端中,可以通过配置向客户端代理添加行为:

代码语言:javascript
运行
复制
<behaviors>
  <endpointBehaviors>
    <behavior name="myBehavior">
      <clientCredentials>
        <windows allowedImpersonationLevel="Impersonation" />
      </clientCredentials>
    </behavior>
  </endpointBehaviors>
</behaviors>

或在守则中:

代码语言:javascript
运行
复制
proxy.ClientCredentials.Windows.AllowImpersonationLevel = TokenImpersonationLevel.Impersonation;

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

如果使用ASMX代理,请确保您是通过你的证书

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

票数 3
EN

Stack Overflow用户

发布于 2011-07-13 10:02:02

看起来,log4net库与这个模拟级别是无法兼容的。如果您删除引用,它将工作。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6676938

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档