每个端点的WCF不同的认证方法不同、方法、WCF

2023-09-07 00:18:38 作者:內心de憔悴感

我有一个WCF服务。我的服务有两个端点,每个都有不同的联系人。该服务使用自定义用户名认证(在下的customUserNamePasswordValidatorType属性定义)的问题是,既endpoins将使用相同​​anthentication方法

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.

反正我有可以为每个端点定义不同anthentication方法?

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.

这是我的app.config

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>

这是自定义的身份验证方法。如果我能在某处传入叫的appName第三个参数,这也将正常工作。

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)
    {

    }
}

多谢

推荐答案

看起来没有办法比劈裂服务等。我会通过将用户名作为用户@应用破解它,并让服务器处理。

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.