public static IHost DefaultTcpSecurizedHost <TContract>(this IHost me, int port, string path, X509Certificate2 certificate, Action <string, string> userNamePasswordValidationAction, Func <ITcpBinding, ITcpBinding> configureTcpBinding = null, Func <IServiceCredentials, IServiceCredentials> configureServiceCredentials = null) { var host = me.AddEndpoint(e => { e = e.WithContractOfType <TContract>(); e = e.WithTcpBinding(b => { b = b.SecurityMode(System.ServiceModel.SecurityMode.Message); b = b.ClientCredentialType(MessageCredentialType.UserName); if (configureTcpBinding != null) { b = configureTcpBinding(b); } }); e = e.WithAddress($"net.tcp://localhost:{port}/{path}"); }); host = host.WithCredentials(c => { c = c.ServiceCertificate(certificate); c = c.UserNamePasswordValidationMode(System.ServiceModel.Security.UserNamePasswordValidationMode.Custom); c = c.CustomUserNamePasswordValidator(userNamePasswordValidationAction); if (configureServiceCredentials != null) { c = configureServiceCredentials(c); } }); return(host); }
public static IHost DefaultTcpUnsecureHost <TContract>(this IHost me, int port, string path, Func <ITcpBinding, ITcpBinding> configureTcpBinding = null, Func <IServiceCredentials, IServiceCredentials> configureServiceCredentials = null) { var host = me.AddEndpoint(e => { e = e.WithContractOfType <TContract>(); e = e.WithTcpBinding(b => { b = b.SecurityMode(System.ServiceModel.SecurityMode.None); if (configureTcpBinding != null) { b = configureTcpBinding(b); } }); e = e.WithAddress($"net.tcp://localhost:{port}/{path}"); }); host = host.WithCredentials(c => { if (configureServiceCredentials != null) { c = configureServiceCredentials(c); } }); return(host); }