尝试模拟时出现WCF用户身份问题

时间:2014-07-24 14:49:27

标签: asp.net .net wcf silverlight impersonation

我有其他公司编写的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) 

1 个答案:

答案 0 :(得分:0)

我已经解决了我的问题。

要将ImpersonationLevel从标识切换为模拟,您必须更新客户端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将使用标识