Exemplo n.º 1
0
        public static IProxy <TContract> DefaultTcpSecurizedProxy <TContract>(this IProxy <TContract> me,
                                                                              string host, int port, string path, string dnsName, string username, string password, string certificateThumbprint,
                                                                              Func <ITcpBinding, ITcpBinding> configureTcpBinding = null,
                                                                              Func <IClientCredentials, IClientCredentials> configureClientCredentials = null,
                                                                              Action <ChannelFactory <TContract> > configureChannelFactory             = null)
        {
            var proxy = me.AddEndpoint(e => {
                e = e.WithContractOfType <TContract>();
                e = e.WithTcpBinding(b => {
                    b = b.ClientCredentialType(MessageCredentialType.UserName);
                    b = b.SecurityMode(System.ServiceModel.SecurityMode.Message);
                    if (configureTcpBinding != null)
                    {
                        b = configureTcpBinding(b);
                    }
                });
                e = e.WithAddress($"net.tcp://{host}:{port}/{path}", dnsName);
            });

            proxy = proxy.WithCredentials(c => {
                c = c.UserName(username);
                c = c.Password(password);
                c = c.ServiceCertificate_ValidationMode(X509CertificateValidationMode.Custom);
                c = c.ServiceCertificate_CustomCertificateValidator(certificateThumbprint);
                if (configureClientCredentials != null)
                {
                    c = configureClientCredentials(c);
                }
            });
            configureChannelFactory?.Invoke((proxy as _Proxy <TContract>).ChannelFactory);
            return(proxy);
        }
Exemplo n.º 2
0
        public static IProxy <TContract> DefaultTcpUnsecureProxy <TContract>(this IProxy <TContract> me, string host, int port, string path,
                                                                             Func <ITcpBinding, ITcpBinding> configureTcpBinding = null,
                                                                             Func <IClientCredentials, IClientCredentials> configureClientCredentials = null,
                                                                             Action <ChannelFactory <TContract> > configureChannelFactory             = null)
        {
            var proxy = 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://{host}:{port}/{path}");
            });

            proxy = proxy.WithCredentials(c => {
                if (configureClientCredentials != null)
                {
                    c = configureClientCredentials(c);
                }
            });
            configureChannelFactory?.Invoke((proxy as _Proxy <TContract>).ChannelFactory);
            return(proxy);
        }