【发布时间】: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的世界里,加<authentication mode="Windows"/>和<identity impersonate="true"/>就这么简单
【问题讨论】:
标签: wcf web-services wcf-binding impersonation wcf-security