【问题标题】:WCF user identity issue when try to impersonate尝试模拟时出现 WCF 用户身份问题
【发布时间】:2014-09-16 04:54:31
【问题描述】:

我有其他公司编写的 WCF 3.5 服务,但我有源代码。我有两个客户,第一个是 Silverlight(由同一家公司编写),第二个是我创建的 ASP 页面。

我在 WCF 网站上出现以下错误:

using(((WindowsIdentity)HttpContext.Current.User.Identity).Impersonate())
{
    SomeClass.SomeMethod();
}

身份几乎一样。

silverlight 调用的身份:

Name=Contoso\Administrator
Authenticated=True
Type=Negotiate
ImpersonationLevel=**Impersonation**
IsAnonymous=False
IsGuest=False
IsSystem=False

ASP Web 调用的身份:

Name=Contoso\Administrator
Authenticated=True
Type=Negotiate
ImpersonationLevel=**Identification**
IsAnonymous=False
IsGuest=False
IsSystem=False

所以区别在于 ImpresonationLevel 值。你知道我该如何解决它吗?

例外:

System.IO.FileLoadException: Could not load file or assembly 'System.Transactions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. Either a required impersonation level was not provided, or the provided impersonation level is invalid. (Exception from HRESULT: 0x80070542)
File name: 'System.Transactions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' ---> System.Runtime.InteropServices.COMException (0x80070542): Either a required impersonation level was not provided, or the provided impersonation level is invalid. (Exception from HRESULT: 0x80070542)

Server stack trace: 
   at System.ServiceModel.Channels.ServiceChannel.OnAbort()
   at System.ServiceModel.Channels.CommunicationObject.Abort()
   at System.ServiceModel.Channels.CommunicationObject.Close(TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.System.IDisposable.Dispose()

Exception rethrown at [0]: 
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at System.IDisposable.Dispose()
   at Microsoft.ResourceManagement.Client.WsTransfer.WsTransferClient.Put(Message request) 
   at Microsoft.ResourceManagement.Client.WsTransfer.WsTransferClient.Put(PutRequest request) 
   at Microsoft.ResourceManagement.Client.DefaultClient.Put(RmResourceChanges transaction) 
   at SomeClass.SomeMethod(some_parames) 

【问题讨论】:

    标签: asp.net .net wcf silverlight impersonation


    【解决方案1】:

    我的问题已经解决了。

    要将 ImpersonationLevel 从 Identification 切换到 Impersonation,您必须更新客户端 wcf 行为配置。它应该看起来像这样(最重要的是 allowedImpersonationLevel 属性):

    <system.serviceModel>   
        <client>
          <endpoint ... 
                    behaviorConfiguration="ImpersonationBehavior" />
        </client>
        <behaviors>
           <endpointBehaviors>
              <behavior name="ImpersonationBehavior">
                 <clientCredentials>
                      <windows allowedImpersonationLevel="Impersonation" />
                 </clientCredentials>
              </behavior>
           </endpointBehaviors>
        </behaviors>
    </system.serviceModel>
    

    如果未指定任何内容,默认情况下 WCF 使用 标识

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-03-13
      • 2015-09-04
      • 2021-07-05
      • 1970-01-01
      • 1970-01-01
      • 2021-02-11
      • 1970-01-01
      相关资源
      最近更新 更多