2011-05-13 32 views
2

我有一個客戶用戶名/密碼驗證器。是否足夠使它在web.config中的endpoints bindingConfiguration屬性中,或者是否需要在Service方法中顯式調用它。我注意到,當我不稱它爲服務操作時,它不會被調用。難道我做錯了什麼?只需要在web.config端點BindingConfiguration中具有自定義用戶名驗證程序就足夠了嗎?

這是我有我的綁定部分定義:

<bindings> 
    <wsHttpBinding> 
    <binding name="CustomAuthentication"> 
     <security mode="Message"> 
     <message clientCredentialType="UserName"/> 
     </security> 
    </binding> 
    </wsHttpBinding> 
</bindings> 

這是我有我的服務節點定義:

<service behaviorConfiguration="CustomValidator" name="Test.TestService"> 

我的端點屬性都有其BindingConfiguration = 「CustomAuthentication」

這就是我在我的ServiceBehavior中定義的行爲:

<behavior name="CustomValidator"> 
     <serviceCredentials> 
     <userNameAuthentication userNamePasswordValidationMode="Custom" 
           customUserNamePasswordValidatorType="Test.CustomUserNameValidator, FuzionSync"/> 

     <serviceCertificate findValue="MyWebSite" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName"/> 

     </serviceCredentials> 

     <serviceMetadata httpGetEnabled="True"/> 

    </behavior> 

當我運行wcf測試客戶端來調用服務調用時,它甚至不調用Validate方法。我需要調用的唯一方法是如果我將它放入一個明確調用的操作中。

+0

如果我是對的,在連接到wcf服務之前,您需要將這些用作證書。 – BreakHead 2011-05-13 14:03:41

+0

@BreakHead,我對你的迴應感到困惑? – Xaisoft 2011-05-13 14:07:55

回答

3

您需要在綁定配置和服務行爲中指定它。這是它的外觀在我們的項目中的一個(重要的部分是clientCredentialType="UserName"<serviceCredentials>元素):

<bindings> 
    <wsHttpBinding> 
    <binding name="SSLWithCustomAuthentication"> 
     <security mode="TransportWithMessageCredential"> 
     <transport clientCredentialType="None" proxyCredentialType="None" /> 
     <message clientCredentialType="UserName" 
       negotiateServiceCredential="true" 
       algorithmSuite="Default" /> 
     </security> 
    </binding> 
    </wsHttpBinding> 
</bindings> 

<behaviors> 
    <serviceBehaviors> 
    <behavior name="customAuthenticationBehavior"> 
     <serviceCredentials> 
     <userNameAuthentication 
      userNamePasswordValidationMode="Custom" 
      customUserNamePasswordValidatorType="Namespace.YourValidator, AssemblyName"/> 
     </serviceCredentials> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 

,然後讓你的服務使用behaviorConfiguration="customAuthenticationBehavior"

請注意,我不認爲WCF讓你使用用戶名身份驗證沒有SSL。

+0

我會更新我的帖子,告訴你我是如何擁有它的。 – Xaisoft 2011-05-13 14:19:23

+0

我更新我的帖子。我在本地機器上有一個臨時的SSL證書。 – Xaisoft 2011-05-13 14:24:59

+0

看起來不錯。順便說一下,服務操作本身在客戶端連接時被調用,還是什麼也不發生? – 2011-05-13 14:55:59

相關問題