开发者

Impersonation in self-hosted WCF?

I'm currently developing a WCF service self hosted in a Windows service with the Self-Hosted SL Svc template. The template works as it should be and I'm able to make calls from my Silverlight application, but when I tried to modify the project to use Impersonation:

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

It throws me an exception during host.Open();:

System.InvalidOperationException was unhandled Message=The contract operation 'GetData' requires Windows identity for automatic impersonation. A Windows identity that represents the caller is not provided by binding ('CustomBinding','http://tempuri.org/') for contract ('IService1','http://tempuri.org/'.

This is my configuration:

<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/>
    &开发者_Go百科lt;/behavior>
  </endpointBehaviors>
</behaviors>

What do I have to change to make this work? do I need to add some configuration to my Silverlight client too?

Thanks in advance :)


I haven't used custom bindings (yet), but this blog entry may give you some help: http://geekswithblogs.net/robz/archive/2007/10/03/wcf-impersonation---specifying-windows-authentication-credentials-on-the-service.aspx


Well after a long search, I've come up with two solutions, one I found at MSDN:

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

The other one was at the Silverlight forums:

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

Don't know what is the major difference between these two, I've managed to open the service and call it from Silverlight successfully. If someone call elaborate on the difference, I would appreciate it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜