【问题标题】:Impersonation using WCF使用 WCF 进行模拟
【发布时间】:2011-03-18 22:45:49
【问题描述】:

我试图通过 WCF Web 服务公开使用用户凭据访问 SQL 服务器(通过实体框架)的功能(这是客户端/dba 要求,因为审计触发器等。放弃试图说服他们不要使用用户的凭据)

我无法让 WCF 实施模拟。 (事实上​​它是一场噩梦)。我已经添加了

[OperationBehavior(Impersonation = ImpersonationOption.Allowed)]

归因于我的合同。但随后它抱怨 BasicHttpContract 无法进行 Window Impersonation。我试图将其更改为 wsHttpBinding。现在元数据交换被破坏了。到目前为止,我只是尝试在 Internet Explorer 中打开服务,甚至还没有开始与客户端连接。 web.config 的相关部分如下所示

<behaviors>
  <serviceBehaviors>
    <behavior name="AssetManagerBehavior">
      <serviceAuthorization impersonateCallerForAllOperations="true" />
      <!--
      -->
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
      <serviceMetadata httpGetEnabled="true" />
      <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

    <services>
        <service name="AssetManager.ServiceInterface" behaviorConfiguration="AssetManagerBehavior">
            <endpoint  address="" binding="wsHttpBinding" contract="IAssetServices">
            </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> 
        </service>
    </services>

<bindings>
  <wsHttpBinding>
    <binding name="test">
      <security mode="TransportWithMessageCredential" />
    </binding>
  </wsHttpBinding>
</bindings>

相关的服务接口类看起来是这样的

namespace AssetManager.ServiceInterface
{
[ServiceContract]
public interface IAssetServices
    { 
        [OperationContract]
        EmployeeDTO CreateNewEmployee(string firstName, string lastName);
    }
}

实际的实现是这样的

namespace AssetManager.ServiceInterface
{
public class AssetManagerServices : IAssetServices
{

    #region IAssetServices Members

    [OperationBehavior(Impersonation = ImpersonationOption.Allowed)]
    public EmployeeDTO CreateNewEmployee(string firstName, string lastName)
    {
    }
 }
}

我正在使用 VS 2010、.net 4、IIS 7(启用了以下身份验证 - 匿名、ASP.NET 模拟、基本身份验证、摘要式身份验证和 Windows 身份验证)。在 IIS 的根 Web 服务器上,我单击 ISAPI 和 CGI​​ 限制并允许访问所有扩展(asp.net 4.0 可能是相关的)

我目前的障碍是当我浏览到 IE 中的位置时,它显示“此服务的元数据发布当前已禁用”。这也不允许我添加服务引用。

最后一点,做 Windows 模拟肯定不会这么困难。使用 WCF 模拟 Web 服务的建议方法是什么?在asp.net的世界里,加&lt;authentication mode="Windows"/&gt;&lt;identity impersonate="true"/&gt;就这么简单

【问题讨论】:

    标签: wcf web-services wcf-binding impersonation wcf-security


    【解决方案1】:

    如果您使用的是传输级安全性,那么它将使用 https 协议,而不是 http。

    你需要设置

    <serviceMetadata httpsGetEnabled=true />
    

    (您目前只有 httpGetEnabled)。

    【讨论】:

    • 不,那不行。现在我收到“此服务的安全设置需要'匿名'身份验证...”异常。我已在 IIS 中关闭匿名身份验证以进行客户端模拟。我可以让它工作的唯一方法是将 wsBinding 更改为 basicBinding 并使用这个 但是现在,我无法添加服务引用我的前端项目,因为它给了我一个错误,提示“元数据包含无法在未经授权的匿名中解析 http 请求的引用”
    猜你喜欢
    • 2011-09-27
    • 2012-09-05
    • 1970-01-01
    • 1970-01-01
    • 2020-08-20
    • 2017-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多