简体   繁体   English

调用ASMX的WCF模拟错误

[英]WCF Impersonation Error Calling ASMX

I have a web app that is calling a WCF Method with Impersonation set as required. 我有一个Web应用程序,该应用程序根据需要调用具有模拟设置的WCF方法。 In this method, I need to call another web service (ASMX) that returns security groups. 在这种方法中,我需要调用另一个返回安全组的Web服务(ASMX)。 The problem is, with the Impersonation set as Required, I get an error when I try to create an instance of the ASMX service. 问题是,将“模拟”设置为“必需”时,尝试创建ASMX服务的实例时出现错误。

WCF Service Method WCF服务方法

[OperationBehavior(Impersonation = ImpersonationOption.Required)]
public List<MacroTypeInfo> GetFilteredMacroDataTypes(MacroDataTypeSection section)
{

    // Errors out here
    using (var login = new local.intranet.webservices.login())
    {
        login.getSecurityGroupsForUser(); // Never gets to this line
    }    

}

The error I get is 我得到的错误是

Either a required impersonation level was not provided, or the provided    
impersonation level is invalid. (Exception from HRESULT: 0x80070542)

Is there something else I must do to be able to call this web service insides this Impersonation required method? 为了能够在“模拟所需的方法”内部调用此Web服务,我还必须做其他事情吗? As soon as I remove the OperationBehavior attribute, the call works. 删除OperationBehavior属性后,该调用即开始工作。

A server cannot impersonate a client to a remote server unless given permission. 除非获得许可,否则服务器无法将客户端模拟到远程服务器。 You can read about the different levels of impersonation here 您可以在此处阅读有关模拟的不同级别的信息

If such impersonation is required the client has to allow it explicitly with an impersonation level of Delegation . 如果需要这样的模拟客户端必须与模拟级别的明确允许其Delegation

You can achieve this in a WCF client with the following endpoint behavior configuration: 您可以通过以下端点行为配置在WCF客户端中实现此目的:

<endpointBehaviors>
    <behavior name="delegateIdentity">
      <clientCredentials>
        <windows allowedImpersonationLevel="Delegation"/>
      </clientCredentials>
    </behavior>
</endpointBehaviors>

If you're using a generated proxy you can set this value on the proxy: 如果您使用的是生成的代理,则可以在代理上设置以下值:

client.ChannelFactory.Credentials.Windows.AllowedImpersonationLevel =
    System.Security.Principal.TokenImpersonationLevel.Delegation;

Lastly if you're creating you proxy with a ChannelFactory<T> you can just set the same value as above on you ChannelFactory<T> . 最后,如果你创建你代理ChannelFactory<T>你可以设置相同的值作为上述对你ChannelFactory<T>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM