views:

159

answers:

2

I have a WCF service. My service has 2 endpoints each of which has a different contact. The service uses custom user name authentication (defined in the customUserNamePasswordValidatorType attribute of under ) The problem is that both endpoins will use the same anthentication method.

Is there anyway I can define different anthentication method for each endpoint?

Each endpoint is accessed by a different and only one app. So if I can pass in the app name to the authentication method, what would also work.

This is my app.config

    <services>
      <service behaviorConfiguration="Behavior1" name="MyServer.Service">
        <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
        <endpoint address="" binding="netTcpBinding" bindingConfiguration="Binding1" contract="MyServer.IService" />
        <endpoint address="service2" binding="netTcpBinding" bindingConfiguration="Binding1" contract="MyServer.ISecondService" />
        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://localhost:37100/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="Behavior1">
          <serviceDebug includeExceptionDetailInFaults="true" />
          <serviceMetadata />
          <serviceCredentials>
            <userNameAuthentication customUserNamePasswordValidatorType="MyServer.Authentication" userNamePasswordValidationMode="Custom" />
          </serviceCredentials>
        </behavior>
      </serviceBehaviors>
    </behaviors>

This is the custom authentication method. If I can somewhere pass in a third parameter called appName, that would also work.

public class Authentication : UserNamePasswordValidator
{
    public override void Validate(string userName, string password)
    {

    }
}

Thanks a lot

A: 

Split your services out into seperate service elements then you can create a behavior for each.

DaveB
A: 

Looks like there's no way other than spliting the service. I am going to hack it by passing the username as "user@app" and have the server deal with it.

David