[Mono-dev] WCF and TransportCredentialOnly

rjhdakota rjh at homeseer.com
Wed Feb 16 10:36:51 EST 2011


I am having what I believe is the same problem. You say basic authentication
is working, any examples? Our project needs the ability to authorize a
connection, and currently we cannot. Here is the code that works on Windows
but allows anyone to connect on MONO: 

Public Sub WCFStartService() 
        ' http service, one-way 

        Dim binding = New
BasicHttpBinding(System.ServiceModel.BasicHttpSecurityMode.TransportCredentialOnly) 
        binding.Security.Transport.ClientCredentialType =
HttpClientCredentialType.Basic 

        Dim address = New Uri("http://192.168.1.129:8080") 
        ServiceHost = New ServiceHost(GetType(HelloService)) 

       
ServiceHost.Credentials.UserNameAuthentication.UserNamePasswordValidationMode
= Security.UserNamePasswordValidationMode.Custom 
       
ServiceHost.Credentials.UserNameAuthentication.CustomUserNamePasswordValidator
= New CustomUserNameValidator 

        ServiceHost.AddServiceEndpoint(GetType(IHelloService), binding,
address) 
        ServiceHost.Open() 
    End Sub 

Public Class CustomUserNameValidator 
        Inherits IdentityModel.Selectors.UserNamePasswordValidator 

        Public Overrides Sub Validate(ByVal userName As String, ByVal
password As String) 
            If Nothing = userName OrElse Nothing = password Then 
                Throw New ArgumentNullException() 
            End If 

            If Not (userName = "user" AndAlso password = "pass") Then 
                ' This throws an informative fault to the client. 
                Throw New FaultException("Unknown Username or Incorrect
Password") 
                ' When you do not want to throw an infomative fault to the
client, 
                ' throw the following exception. 
                ' Throw New SecurityTokenException("Unknown Username or
Incorrect Password") 
            End If 

        End Sub 


    End Class
-- 
View this message in context: http://mono.1490590.n4.nabble.com/WCF-and-TransportCredentialOnly-tp3307532p3309082.html
Sent from the Mono - Dev mailing list archive at Nabble.com.


More information about the Mono-devel-list mailing list