【问题标题】:Impersonation in self-hosted WCF?自托管 WCF 中的模拟?
【发布时间】:2011-06-30 05:53:05
【问题描述】:

我目前正在使用Self-Hosted SL Svc 模板开发自托管在Windows 服务中的WCF 服务。 该模板可以正常工作,并且我可以从我的 Silverlight 应用程序中进行调用,但是当我尝试修改项目以使用模拟时:

[OperationBehavior(Impersonation = ImpersonationOption.Required)]
public string GetData(int value)
{
    return string.Format("You entered: {0}", value);
}

它在host.Open(); 期间抛出了一个异常:

System.InvalidOperationException 是 未处理的消息=合同 操作“GetData”需要 Windows 自动模仿的身份。 一个 Windows 标识,代表 调用者不是由绑定提供的 ('CustomBinding','http://tempuri.org/') 对于合同 ('IService1','http://tempuri.org/'.

这是我的配置:

<system.serviceModel>
<bindings>
  <customBinding>
    <binding name="binaryHttpBinding">
      <binaryMessageEncoding/>
      <httpTransport/>
    </binding>
  </customBinding>
</bindings>
<services>
  <service name="SLServiceLibrary.Service1" behaviorConfiguration="SLServiceLibrary.ServiceBehavior">
    <endpoint address="Service1" binding="customBinding" contract="SLServiceLibrary.IService1" bindingConfiguration="binaryHttpBinding"/>
    <endpoint address="" binding="webHttpBinding" contract="SLServiceLibrary.IClientAccessPolicy" behaviorConfiguration="webHttpEnablingBehavior"/>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8733/"/>
      </baseAddresses>
    </host>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="SLServiceLibrary.ServiceBehavior">
      <serviceMetadata httpGetEnabled="True"/>
      <serviceDebug includeExceptionDetailInFaults="False"/>
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior name="webHttpEnablingBehavior">
      <webHttp/>
    </behavior>
  </endpointBehaviors>
</behaviors>

我必须进行哪些更改才能使其正常工作?我还需要为我的 Silverlight 客户端添加一些配置吗?

提前致谢:)

【问题讨论】:

    标签: c# silverlight wcf impersonation


    【解决方案1】:

    【讨论】:

      【解决方案2】:

      经过长时间的搜索,我想出了两个解决方案,一个是在MSDN找到的:

      <bindings>
        <customBinding>
          <binding name="binaryHttpBinding">
            <binaryMessageEncoding/>
            <httpTransport authenticationScheme="Ntlm"/>
          </binding>
        </customBinding>
      </bindings>
      

      另一个在Silverlight forums

      <bindings>
        <customBinding>
          <binding name="binaryHttpBinding">
            <binaryMessageEncoding/>
            <httpTransport authenticationScheme="Negotiate"/>
          </binding>
        </customBinding>
      </bindings>
      

      不知道这两者之间的主要区别是什么,我已经成功打开服务并从 Silverlight 调用它。如果有人打电话详细说明差异,我将不胜感激。

      【讨论】:

      • 根据this MSDN article Negotiate 可以更快,因为它使用 Kerberos 协议(如果可用(更快))或 NTLM 身份验证(如果不可用)。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-01
      相关资源
      最近更新 更多