public void BusinessToBusinessCert_BasicHttp() { string uri = "http://localhost/servicehelpers"; using (var host = new ServiceHost(typeof(BusinessToBusiness1), new Uri(uri))) { host.AddServiceEndpoint(typeof(IBusinessToBusiness1), new BasicHttpBinding(), uri); host.Open(); // raw proxy var clientBinding = new WS2007HttpBinding(SecurityMode.Message); clientBinding.Security.Message.ClientCredentialType = MessageCredentialType.Certificate; clientBinding.Security.Message.EstablishSecurityContext = false; EndpointIdentity identity = new DnsEndpointIdentity("RawTcpServiceCert1"); var factory = new ChannelFactory <IBusinessToBusiness1>(clientBinding, new EndpointAddress(new Uri(uri), identity)); factory.Credentials.ClientCertificate.SetCertificate( "CN=RawTcpClientCert1", System.Security.Cryptography.X509Certificates.StoreLocation.LocalMachine, System.Security.Cryptography.X509Certificates.StoreName.My); factory.Credentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.PeerTrust; var channel = factory.CreateChannel(); Assert.AreEqual("hi", channel.TestMe("hi")); factory.Close(); } }
public static void SameBinding_SecurityModeTransport_ClientCredentialTypeCertificate_EchoString() { string testString = "Hello"; ChannelFactory <IWcfService> factory = null; IWcfService serviceProxy = null; try { // *** SETUP *** \\ CustomBinding binding = new CustomBinding( new SslStreamSecurityBindingElement(), // This is the binding element used when Security.Mode = TransportWithMessageCredentials new BinaryMessageEncodingBindingElement(), new TcpTransportBindingElement()); var endpointIdentity = new DnsEndpointIdentity(Endpoints.Tcp_CustomBinding_SslStreamSecurity_HostName); factory = new ChannelFactory <IWcfService>(binding, new EndpointAddress(new Uri(Endpoints.Tcp_CustomBinding_SslStreamSecurity_Address), endpointIdentity)); serviceProxy = factory.CreateChannel(); // *** EXECUTE *** \\ string result = serviceProxy.Echo(testString); // *** VALIDATE *** \\ Assert.Equal(testString, result); // *** CLEANUP *** \\ ((ICommunicationObject)serviceProxy).Close(); factory.Close(); } finally { // *** ENSURE CLEANUP *** \\ ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, factory); } }
private ITracktorService CreateServiceClient() { var uri = new Uri(Configuration["Tracktor:ServiceUrl"]); HttpBindingBase httpBinding; if (uri.Scheme == "http") { var binding = new BasicHttpBinding(); binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic; httpBinding = binding; } else { var binding = new BasicHttpsBinding(BasicHttpsSecurityMode.Transport); binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic; httpBinding = binding; } var identity = new DnsEndpointIdentity(""); var address = new EndpointAddress(uri, identity, new AddressHeader[0]); var factory = new ChannelFactory <ITracktorService>(httpBinding, address); ClientCredentials loginCredentials = new ClientCredentials(); loginCredentials.UserName.UserName = "******"; loginCredentials.UserName.Password = Configuration["Tracktor:ServicePassword"]; var defaultCredentials = factory.Endpoint.EndpointBehaviors.OfType <ClientCredentials>().First(); factory.Endpoint.EndpointBehaviors.Remove(defaultCredentials); factory.Endpoint.EndpointBehaviors.Add(loginCredentials); return(factory.CreateChannel()); }
public static void DefaultSettings_Tcp_Binary_Echo_RoundTrips_String() { string testString = "Hello"; ChannelFactory <IWcfService> factory = null; IWcfService serviceProxy = null; try { // *** SETUP *** \\ CustomBinding binding = new CustomBinding( new SslStreamSecurityBindingElement(), new BinaryMessageEncodingBindingElement(), new TcpTransportBindingElement()); var endpointIdentity = new DnsEndpointIdentity(Endpoints.Tcp_CustomBinding_SslStreamSecurity_HostName); factory = new ChannelFactory <IWcfService>(binding, new EndpointAddress(new Uri(Endpoints.Tcp_CustomBinding_SslStreamSecurity_Address), endpointIdentity)); factory.Credentials.ServiceCertificate.Authentication.RevocationMode = X509RevocationMode.NoCheck; serviceProxy = factory.CreateChannel(); // *** EXECUTE *** \\ string result = serviceProxy.Echo(testString); // *** VALIDATE *** \\ Assert.Equal(testString, result); // *** CLEANUP *** \\ ((ICommunicationObject)serviceProxy).Close(); factory.Close(); } finally { // *** ENSURE CLEANUP *** \\ ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, factory); } }
public void Open() { if (State != CommunicationState.Created) { return; } try { Opening(this, EventArgs.Empty); ServiceBusHelper.ConfigureBinding(Binding, Anonymous); m_Proxies = new Dictionary <string, T>(); IServiceBusProperties properties = this; foreach (Uri uri in properties.Addresses) { EndpointIdentity identity = new DnsEndpointIdentity(m_ServiceCertFindValue.ToString()); EndpointAddress address = new EndpointAddress(uri, identity); ChannelFactory <T> factory = new ChannelFactory <T>(Binding, address); //Set credentials for message security (if needed) factory.Credentials.UserName.UserName = ServiceUsername; //could be null factory.Credentials.UserName.Password = ServicePassword; //could be null //Set service cert to secure message ClientCredentials behavior = factory.Endpoint.Behaviors.Find <ClientCredentials>(); behavior.ServiceCertificate.SetDefaultCertificate(m_ServiceCertLocation, m_ServiceCertStoreName, m_ServiceCertFindType, m_ServiceCertFindValue); //Set service bus creds if (properties.Credential == null) { if (m_Secret != null) { factory.SetServiceBusCredentials(m_Issuer, m_Secret); } } else { Debug.Assert(m_Secret == null); factory.Endpoint.Behaviors.Add(properties.Credential); } string methodName = uri.Segments[uri.Segments.Length - 1]; methodName = methodName.Replace("/", ""); m_Proxies[methodName] = factory.CreateChannel(); ICommunicationObject proxy = m_Proxies[methodName] as ICommunicationObject; proxy.Open(); } State = CommunicationState.Opened; Opened(this, EventArgs.Empty); } catch { State = CommunicationState.Faulted; } }
public static void Ctor_NullDnsName() { string dnsName = null; Assert.Throws <ArgumentNullException>("dnsName", () => { DnsEndpointIdentity dnsEndpointEntity = new DnsEndpointIdentity(dnsName); }); }
protected override T CreateChannel() { if (Endpoint.Address.Identity == null) { string namespaceBaseAddress = ServiceBusHelper.ExtractNamespace(Endpoint.Address.Uri); Uri address = Endpoint.Address.Uri; EndpointIdentity identity = new DnsEndpointIdentity(namespaceBaseAddress); Endpoint.Address = new EndpointAddress(address, identity); } return(base.CreateChannel()); }
public void SetServiceCertificate(object findValue, StoreLocation location, StoreName storeName, X509FindType findType) { ClientCredentials behavior = Endpoint.Behaviors.Find <ClientCredentials>(); behavior.ServiceCertificate.SetDefaultCertificate(location, storeName, findType, findValue); if (Endpoint.Address.Identity == null) { Uri address = Endpoint.Address.Uri; EndpointIdentity identity = new DnsEndpointIdentity(findValue.ToString()); Endpoint.Address = new EndpointAddress(address, identity); } }
public static ITracktorService Create() { var httpBinding = new BasicHttpsBinding("BasicHttpsBinding_ITracktorService"); var identity = new DnsEndpointIdentity(""); var address = new EndpointAddress(new Uri(ConfigurationManager.AppSettings["ServiceUrl"]), identity, new AddressHeaderCollection()); var factory = new ChannelFactory <ITracktorService>(httpBinding, address); ClientCredentials loginCredentials = new ClientCredentials(); loginCredentials.UserName.UserName = "******"; loginCredentials.UserName.Password = ConfigurationManager.AppSettings["ServicePassword"]; var defaultCredentials = factory.Endpoint.Behaviors.Find <ClientCredentials>(); factory.Endpoint.Behaviors.Remove(defaultCredentials); factory.Endpoint.Behaviors.Add(loginCredentials); return(factory.CreateChannel()); }
public static void DefaultSettings_Tcp_Binary_Echo_RoundTrips_String() { #if FULLXUNIT_NOTSUPPORTED bool root_Certificate_Installed = Root_Certificate_Installed(); bool client_Certificate_Installed = Client_Certificate_Installed(); if (!root_Certificate_Installed || !client_Certificate_Installed) { Console.WriteLine("---- Test SKIPPED --------------"); Console.WriteLine("Attempting to run the test in ToF, a ConditionalFact evaluated as FALSE."); Console.WriteLine("Root_Certificate_Installed evaluated as {0}", root_Certificate_Installed); Console.WriteLine("Client_Certificate_Installed evaluated as {0}", client_Certificate_Installed); return; } #endif string testString = "Hello"; ChannelFactory <IWcfService> factory = null; IWcfService serviceProxy = null; try { // *** SETUP *** \\ CustomBinding binding = new CustomBinding( new SslStreamSecurityBindingElement(), new BinaryMessageEncodingBindingElement(), new TcpTransportBindingElement()); var endpointIdentity = new DnsEndpointIdentity(Endpoints.Tcp_CustomBinding_SslStreamSecurity_HostName); factory = new ChannelFactory <IWcfService>(binding, new EndpointAddress(new Uri(Endpoints.Tcp_CustomBinding_SslStreamSecurity_Address), endpointIdentity)); serviceProxy = factory.CreateChannel(); // *** EXECUTE *** \\ string result = serviceProxy.Echo(testString); // *** VALIDATE *** \\ Assert.Equal(testString, result); // *** CLEANUP *** \\ ((ICommunicationObject)serviceProxy).Close(); factory.Close(); } finally { // *** ENSURE CLEANUP *** \\ ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, factory); } }
private void CallWcfServiceButton_Click(object sender, RoutedEventArgs e) { var token = ""; if (_response != null && _response.Values.ContainsKey("access_token")) { //client.SetBearerToken(_response.AccessToken); token = _response.AccessToken; } CustomBinding customTokenBinding = CreateCustomTokenBinding(); customTokenBinding.ReceiveTimeout = new TimeSpan(12, 0, 0); customTokenBinding.SendTimeout = new TimeSpan(12, 0, 0); customTokenBinding.OpenTimeout = new TimeSpan(12, 0, 0); customTokenBinding.CloseTimeout = new TimeSpan(12, 0, 0); var endPointIdentity = new DnsEndpointIdentity("idsrv3test"); var serviceAddress = new EndpointAddress(new Uri("http://localhost:2729/Service1.svc"), endPointIdentity); // Create a client with given client endpoint configuration var channelFactory = new ChannelFactory <IService1>(customTokenBinding, serviceAddress); // configure the credit card credentials on the channel factory CustomTokenClientCredentials credentials = new CustomTokenClientCredentials(token); // configure the service certificate on the credentials credentials.ServiceCertificate.DefaultCertificate = LoadCertificate(); // replace ClientCredentials with CreditCardClientCredentials channelFactory.Endpoint.Behaviors.Remove(typeof(ClientCredentials)); channelFactory.Endpoint.Behaviors.Add(credentials); var client = channelFactory.CreateChannel(); var response = client.GetIdentityData(); ((ICommunicationObject)client).Close(); channelFactory.Close(); Textbox1.Text = response; }
public void Raw_HttpCert_NotFullName() { Stopwatch sw = new Stopwatch(); sw.Start(); string uri = "http://localhost/servicehelpers"; using (var host = new ServiceHost(typeof(RawTcpCertService), new Uri(uri))) { var serviceBinding = new WS2007HttpBinding(SecurityMode.Message); serviceBinding.Security.Message.ClientCredentialType = MessageCredentialType.Certificate; host.Credentials.ServiceCertificate.SetCertificate( "CN=RawTcpServiceCert_2", System.Security.Cryptography.X509Certificates.StoreLocation.LocalMachine, System.Security.Cryptography.X509Certificates.StoreName.My); host.Credentials.ClientCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.PeerTrust; host.AddServiceEndpoint(typeof(IRawTcpCertService), serviceBinding, uri); host.Open(); var clientBinding = new WS2007HttpBinding(SecurityMode.Message); clientBinding.Security.Message.ClientCredentialType = MessageCredentialType.Certificate; EndpointIdentity identity = new DnsEndpointIdentity("RawTcpServiceCert_2"); var factory = new ChannelFactory <IRawTcpCertService>(clientBinding, new EndpointAddress(new Uri(uri), identity)); factory.Credentials.ClientCertificate.SetCertificate( StoreLocation.LocalMachine, StoreName.My, X509FindType.FindBySubjectName, "RawTcpClientCert_"); // NOT FULL NAME factory.Credentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.PeerTrust; var channel = factory.CreateChannel(); Assert.AreEqual("hi", channel.TestMe("hi")); factory.Close(); } sw.Stop(); Trace.WriteLine("total time = " + sw.ElapsedMilliseconds); }
private static EndpointAddress CreateEndpointAddress(Uri endpoint) { var serviceCertificate = CertificateStore.Instance.ServiceCertificate; if (serviceCertificate == null) { throw new ArgumentException("Cannot create client without service certificate - invoke GetBankCertificateIfRequired() to retrieve this."); } var commonName = serviceCertificate.GetNameInfo(X509NameType.SimpleName, false); if (commonName == null) { throw new ArgumentException("Cannot initialize client using service certificate without common name: " + serviceCertificate.SubjectName); } var endpointIdentity = new DnsEndpointIdentity(commonName); //CN in the Bank certificate. This will cause encryption to use this certificate. var ea = new EndpointAddress(endpoint, endpointIdentity, new AddressHeaderCollection()); return(ea); }
public T CreateClient <T>(string bindingName, string wcfUrl, string userName, string password, string identityName) { //绑定 //WSHttpBinding binding = new WSHttpBinding(); //binding.Security.Message.ClientCredentialType = MessageCredentialType.UserName; WSHttpBinding binding = new WSHttpBinding(bindingName); //终结点“标识”属性 Uri myUri = new Uri(wcfUrl); DnsEndpointIdentity ei = new DnsEndpointIdentity(identityName); //"ParkingServer" EndpointAddress address = new EndpointAddress(myUri, ei); //创建通道工厂 ChannelFactory <T> factory = new ChannelFactory <T>(binding, address); factory.Credentials.UserName.UserName = userName; // "admin"; factory.Credentials.UserName.Password = password; // "123456"; //安全证书 ClientCredentials ccs = new ClientCredentials(); ccs.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.Custom; //自动义X509证书验证器 "Jurassic.AppCenter.Wcf.Client.CustomUserValidator,Jurassic.AppCenter.Wcf.Client"; CustomCertificateValidator cuv = new CustomCertificateValidator(); ccs.ServiceCertificate.Authentication.CustomCertificateValidator = cuv; ccs.UserName.UserName = userName; // "admin"; ccs.UserName.Password = password; // "123456"; //增加安全行为配置 factory.Endpoint.Behaviors.Clear(); factory.Endpoint.Behaviors.Add(ccs); //创建 T client = factory.CreateChannel(); return(client); }
public void BusinessToBusinessCert_UseAttribute_CurrentUserCert() { string uri = "http://localhost/servicehelpers/b2b"; using (var host = new ServiceHost(typeof(BusinessToBusinessCurrentUser), new Uri(uri))) { host.AddServiceEndpoint(typeof(IBusinessToBusinessCurrentUser), new WS2007HttpBinding(), uri); host.Open(); var clientBinding = new WS2007HttpBinding(SecurityMode.Message); clientBinding.Security.Message.ClientCredentialType = MessageCredentialType.Certificate; clientBinding.Security.Message.EstablishSecurityContext = false; clientBinding.Security.Message.NegotiateServiceCredential = false; EndpointIdentity identity = new DnsEndpointIdentity("B2BCurrentUserService"); var factory = new ChannelFactory <IBusinessToBusinessCurrentUser>(clientBinding, new EndpointAddress(new Uri(uri), identity)); factory.Credentials.ClientCertificate.SetCertificate( "CN=B2BCurrentUserClient", System.Security.Cryptography.X509Certificates.StoreLocation.CurrentUser, System.Security.Cryptography.X509Certificates.StoreName.My); factory.Credentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.PeerTrust; var serviceCert = "B2BCurrentUserService"; StoreLocation serviceLocation = StoreLocation.LocalMachine; CertHelper.TryGetCertLocation(serviceCert, out serviceLocation, true); factory.Credentials.ServiceCertificate.SetDefaultCertificate( serviceLocation, System.Security.Cryptography.X509Certificates.StoreName.My, X509FindType.FindBySubjectName, serviceCert); factory.Credentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.PeerTrust; var channel = factory.CreateChannel(); Assert.AreEqual("hi", channel.TestMe("hi")); factory.Close(); } }
private static TClient GetClient <TClient, TInterface>( string url, string username, string password, EndpointBindingType bindingType ) where TClient : ClientBase <TInterface> where TInterface : class { System.ServiceModel.Channels.Binding binding = null; TClient client; //DnsEndpointIdentity endpointIdentity = new DnsEndpointIdentity("mytp-eptstsrv01.spritzer.local"); DnsEndpointIdentity endpointIdentity = new DnsEndpointIdentity(Conn.DnsIdentity); var endpointAddress = new EndpointAddress(new Uri(url), endpointIdentity); switch (bindingType) { case EndpointBindingType.BasicHttp: binding = GetBasicHttpBinding(); break; case EndpointBindingType.SOAPHttp: binding = GetWsHttpBinding(); break; } TimeSpan operationTimeout = new TimeSpan(0, 12, 0); binding.CloseTimeout = operationTimeout; binding.ReceiveTimeout = operationTimeout; binding.SendTimeout = operationTimeout; binding.OpenTimeout = operationTimeout; client = (TClient)Activator.CreateInstance(typeof(TClient), binding, endpointAddress); if (!string.IsNullOrEmpty(username) && (client.ClientCredentials != null)) { client.ClientCredentials.UserName.UserName = username; client.ClientCredentials.UserName.Password = password; } return(client); }
private void Raw_HttpCert_Call() { string uri = "http://localhost/servicehelpers"; using (var host = new ServiceHost(typeof(RawTcpCertService), new Uri(uri))) { var serviceBinding = new WS2007HttpBinding(SecurityMode.Message); serviceBinding.Security.Message.ClientCredentialType = MessageCredentialType.Certificate; host.Credentials.ServiceCertificate.SetCertificate( "CN=RawTcpServiceCert1", System.Security.Cryptography.X509Certificates.StoreLocation.LocalMachine, System.Security.Cryptography.X509Certificates.StoreName.My); host.Credentials.ClientCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.PeerTrust; host.AddServiceEndpoint(typeof(IRawTcpCertService), serviceBinding, uri); host.Open(); var clientBinding = new WS2007HttpBinding(SecurityMode.Message); clientBinding.Security.Message.ClientCredentialType = MessageCredentialType.Certificate; EndpointIdentity identity = new DnsEndpointIdentity("RawTcpServiceCert1"); var factory = new ChannelFactory <IRawTcpCertService>(clientBinding, new EndpointAddress(new Uri(uri), identity)); factory.Credentials.ClientCertificate.SetCertificate( "CN=RawTcpClientCert1", System.Security.Cryptography.X509Certificates.StoreLocation.LocalMachine, System.Security.Cryptography.X509Certificates.StoreName.My); factory.Credentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.PeerTrust; var channel = factory.CreateChannel(); Assert.AreEqual("hi", channel.TestMe("hi")); factory.Close(); } }
static void CallServiceCustomToken(string token) { Binding customTokenBinding = CreateCustomTokenBinding(); customTokenBinding.ReceiveTimeout = new TimeSpan(12, 0, 0); customTokenBinding.SendTimeout = new TimeSpan(12, 0, 0); customTokenBinding.OpenTimeout = new TimeSpan(12, 0, 0); customTokenBinding.CloseTimeout = new TimeSpan(12, 0, 0); var endPointIdentity = new DnsEndpointIdentity("idsrv3test"); var serviceAddress = new EndpointAddress(new Uri("http://localhost:2729/Service1.svc"), endPointIdentity); // Create a client with given client endpoint configuration var channelFactory = new ChannelFactory <IService1>(customTokenBinding, serviceAddress); // configure the credit card credentials on the channel factory CustomTokenClientCredentials credentials = new CustomTokenClientCredentials(token); // configure the service certificate on the credentials credentials.ServiceCertificate.DefaultCertificate = LoadCertificate(); // replace ClientCredentials with CreditCardClientCredentials channelFactory.Endpoint.Behaviors.Remove(typeof(ClientCredentials)); channelFactory.Endpoint.Behaviors.Add(credentials); var client = channelFactory.CreateChannel(); var response = client.GetIdentityData(); ((IChannel)client).Close(); channelFactory.Close(); "\n\nService claims:\n".ConsoleGreen(); Console.WriteLine(response); Console.ReadLine(); }
private IChannelFactory <IRequestSessionChannel> CreateChannelFactory(bool useSslStreamSecurity, bool includeExceptionDetails, DnsEndpointIdentity endpointIdentity) { string str; int num = 0; CustomBinding customBinding = SbmpProtocolDefaults.CreateBinding(false, false, 2147483647, useSslStreamSecurity, endpointIdentity); DuplexRequestBindingElement duplexRequestBindingElement = new DuplexRequestBindingElement() { IncludeExceptionDetails = includeExceptionDetails, ClientMode = this.clientMode }; DuplexRequestBindingElement duplexRequestBindingElement1 = duplexRequestBindingElement; int num1 = num; num = num1 + 1; customBinding.Elements.Insert(num1, duplexRequestBindingElement1); BindingParameterCollection bindingParameterCollection = new BindingParameterCollection(); if (useSslStreamSecurity) { ClientCredentials clientCredential = new ClientCredentials(); clientCredential.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.Custom; clientCredential.ServiceCertificate.Authentication.CustomCertificateValidator = RetriableCertificateValidator.Instance; if (SoapProtocolDefaults.IsAvailableClientCertificateThumbprint(out str)) { clientCredential.ClientCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.My, X509FindType.FindByThumbprint, str); } bindingParameterCollection.Add(clientCredential); } this.MessageVersion = customBinding.MessageVersion; return(customBinding.BuildChannelFactory <IRequestSessionChannel>(bindingParameterCollection)); }
public static CustomBinding CreateBinding(bool portSharingEnabled, bool useWebStream, int maxReceivedMessageSize, bool useSslStreamSecurity, DnsEndpointIdentity endpointIdentity) { return(SbmpProtocolDefaults.CreateBinding(portSharingEnabled, useWebStream, false, maxReceivedMessageSize, useSslStreamSecurity, endpointIdentity)); }
public static void Ctor_DnsName(string dnsName) { DnsEndpointIdentity dnsEndpointEntity = new DnsEndpointIdentity(dnsName); }
public static CustomBinding CreateBinding(bool portSharingEnabled, bool useWebStream, bool useHttpsWebStream, int maxReceivedMessageSize, bool useSslStreamSecurity, DnsEndpointIdentity endpointIdentity) { TransportBindingElement tcpTransportBindingElement; BinaryMessageEncodingBindingElement binaryMessageEncodingBindingElement = new BinaryMessageEncodingBindingElement(); binaryMessageEncodingBindingElement.ReaderQuotas.MaxStringContentLength = 50000; bool flag = (useWebStream ? false : useSslStreamSecurity); if (useWebStream) { flag = (useHttpsWebStream ? false : useSslStreamSecurity); } if (!useWebStream) { tcpTransportBindingElement = new TcpTransportBindingElement() { PortSharingEnabled = portSharingEnabled }; } else { tcpTransportBindingElement = new SocketConnectionBindingElement(new WebStreamOnewayClientConnectionElement((flag ? SocketSecurityRole.SslClient : SocketSecurityRole.None), "messaging", useHttpsWebStream), false); } tcpTransportBindingElement.MaxReceivedMessageSize = (long)maxReceivedMessageSize; tcpTransportBindingElement.ManualAddressing = true; CustomBinding customBinding = new CustomBinding(); if (flag) { BindingElementCollection elements = customBinding.Elements; SslStreamSecurityBindingElement sslStreamSecurityBindingElement = new SslStreamSecurityBindingElement() { IdentityVerifier = new LenientDnsIdentityVerifier(endpointIdentity) }; elements.Add(sslStreamSecurityBindingElement); } customBinding.Elements.Add(binaryMessageEncodingBindingElement); customBinding.Elements.Add(tcpTransportBindingElement); return(customBinding); }
public LenientDnsIdentityVerifier(DnsEndpointIdentity expectedIdentity) { this.expectedIdentity = expectedIdentity; }
public static CustomBinding CreateSslBinding(bool portSharingEnabled, int maxReceivedMessageSize, long maxBufferPoolSize, bool clientCertificateAuthEnabled, DnsEndpointIdentity endpointIdentity, IssuedSecurityTokenParameters issuedTokenParameters) { return(SoapProtocolDefaults.CreateBinding(portSharingEnabled, maxReceivedMessageSize, maxBufferPoolSize, true, clientCertificateAuthEnabled, endpointIdentity, issuedTokenParameters)); }
public static CustomBinding CreateBinding(bool portSharingEnabled, int maxReceivedMessageSize, long maxBufferPoolSize, bool useSslStreamSecurity, bool clientCertificateAuthEnabled, DnsEndpointIdentity endpointIdentity, IssuedSecurityTokenParameters issuedTokenParameters) { TransactionFlowBindingElement transactionFlowBindingElement = new TransactionFlowBindingElement(); BinaryMessageEncodingBindingElement binaryMessageEncodingBindingElement = new BinaryMessageEncodingBindingElement(); binaryMessageEncodingBindingElement.ReaderQuotas.MaxStringContentLength = maxReceivedMessageSize; TcpTransportBindingElement tcpTransportBindingElement = new TcpTransportBindingElement() { PortSharingEnabled = portSharingEnabled, MaxReceivedMessageSize = (long)maxReceivedMessageSize, MaxBufferPoolSize = maxBufferPoolSize }; CustomBinding customBinding = new CustomBinding(); customBinding.Elements.Add(transactionFlowBindingElement); if (useSslStreamSecurity) { SslStreamSecurityBindingElement sslStreamSecurityBindingElement = new SslStreamSecurityBindingElement(); if (endpointIdentity != null) { sslStreamSecurityBindingElement.IdentityVerifier = new LenientDnsIdentityVerifier(endpointIdentity); } sslStreamSecurityBindingElement.RequireClientCertificate = clientCertificateAuthEnabled; customBinding.Elements.Add(sslStreamSecurityBindingElement); } customBinding.Elements.Add(binaryMessageEncodingBindingElement); customBinding.Elements.Add(tcpTransportBindingElement); return(customBinding); }
public ContainerChannelManager(bool clientMode, bool useSslStreamSecurity, bool includeExceptionDetails, DnsEndpointIdentity endpointIdentity) { this.clientMode = clientMode; this.onInnerChannelFaulted = new EventHandler(this.OnInnerChannelFaulted); this.defaultChannelFactory = this.CreateChannelFactory(useSslStreamSecurity, includeExceptionDetails, endpointIdentity); this.securedChannelFactory = this.CreateChannelFactory(true, includeExceptionDetails, endpointIdentity); this.defaultChannelFactory.Open(); this.securedChannelFactory.Open(); }
public static void Ctor_DnsName() { string dnsName = "MyDns"; DnsEndpointIdentity dnsEndpointEntity = new DnsEndpointIdentity(dnsName); }