2011-06-13 83 views
0

我希望能夠像使用basicHttpBinding一樣指定我的自定義綁定的安全級別。WCF使用Kerberos配置CustomBinding

<customBinding> 
    <binding name="jsonpBinding" >  
     ....     
     <security mode="TransportCredentialOnly"> 
      <transport clientCredentialType="Windows"/> 
     </security> 
    </binding> 
    </customBinding> 

如何正確地做到這一點,因爲它不被接受?

+2

你甚至嘗試使用谷歌搜索「wcf kerberos」嗎?這回答了你的問題了嗎?第一個結果:http://stackoverflow.com/questions/1295526/wcf-and-kerberos-authentication – Amy 2011-06-13 17:31:20

+0

@Inuyasha這是特定於CustomBinding它與basicHttpBinding工作正常。 – Jonathan 2011-06-13 17:33:46

回答

0

加入authenticationScheme="Negotiate"解決了這個問題。

添加到您的WCF方法

[OperationBehavior(Impersonation = ImpersonationOption.Required)] 
public int Dosomething() 
{ 
... 
} 

添加到您的WCF的web.config

<customBinding>  
    <binding name="jsonpBinding" >    
     <jsonMessageEncoding/> 
     <httpTransport manualAddressing="true" authenticationScheme="Negotiate"/> 
    </binding> 
</customBinding> 

添加以下到您的客戶端(MVC Web應用程序在我的情況)。值得注意的是,svcutil應用程序不會爲您的客戶端存根產生行爲,您必須將其添加爲manualy。這讓我有一段時間!

<client> 
      <endpoint address="..." 
       binding="customBinding" bindingConfiguration="..." 
       contract="..." name="..." behaviorConfiguration="ImpersonationBehavior" />   
     </client> 
     <behaviors> 
      <endpointBehaviors> 
      <behavior name="ImpersonationBehavior"> 
       <clientCredentials> 
       <windows allowedImpersonationLevel="Impersonation"/> 
       </clientCredentials> 
      </behavior>    
      </endpointBehaviors>   
     </behaviors>