开发者

WCF Different authentication method for each endpoint

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 paramete开发者_如何学Gor called appName, that would also work.

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

    }
}

Thanks a lot


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.


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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜