private static string GetDefaultEndpoint(System.ServiceModel.Channels.Binding binding, string serviceName) { TransportBindingElement transport = binding.CreateBindingElements().Find <TransportBindingElement>(); if (transport != null) { if (typeof(HttpTransportBindingElement) == transport.GetType()) { UriBuilder ub = new UriBuilder(transport.Scheme, "localhost"); ub.Path = serviceName; return(ub.Uri.ToString()); } if (typeof(HttpsTransportBindingElement) == transport.GetType()) { UriBuilder ub = new UriBuilder(transport.Scheme, "localhost"); ub.Path = serviceName; return(ub.Uri.ToString()); } if (typeof(TcpTransportBindingElement) == transport.GetType()) { UriBuilder ub = new UriBuilder(transport.Scheme, "localhost"); ub.Path = serviceName; return(ub.Uri.ToString()); } if (typeof(NamedPipeTransportBindingElement) == transport.GetType()) { return("tbd"); } if (typeof(MsmqTransportBindingElement) == transport.GetType()) { return("tbd"); } } return(""); }
private static string GetTransport(System.ServiceModel.Channels.Binding binding) { TransportBindingElement transport = binding.CreateBindingElements().Find <TransportBindingElement>(); if (transport != null) { if (typeof(HttpTransportBindingElement) == transport.GetType()) { return("http://schemas.xmlsoap.org/soap/http"); } if (typeof(HttpsTransportBindingElement) == transport.GetType()) { return("http://schemas.xmlsoap.org/soap/https"); } if (typeof(TcpTransportBindingElement) == transport.GetType()) { return("http://schemas.microsoft.com/soap/tcp"); } if (typeof(NamedPipeTransportBindingElement) == transport.GetType()) { return("http://schemas.microsoft.com/soap/named-pipe"); } if (typeof(MsmqTransportBindingElement) == transport.GetType()) { return("http://schemas.microsoft.com/soap/msmq"); } } return(""); }
private static BindingElementCollection SafeCreateBindingElements(Binding binding) { if (binding == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("binding"); } return binding.CreateBindingElements(); }
private static BindingElementCollection SafeCreateBindingElements(Binding binding) { if (binding == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("binding"); } return(binding.CreateBindingElements()); }
// Binding passed to .ctor() seems to have nothing to do // with the properties on this class. public CustomBinding(Binding binding) : this(binding.CreateBindingElements(), binding.Name, binding.Namespace) { OpenTimeout = binding.OpenTimeout; CloseTimeout = binding.CloseTimeout; SendTimeout = binding.SendTimeout; ReceiveTimeout = binding.ReceiveTimeout; scheme = binding.Scheme; security = binding as ISecurityCapabilities; }
// Binding passed to .ctor() seems to have nothing to do // with the properties on this class. public CustomBinding (Binding binding) : this (binding.CreateBindingElements (), binding.Name, binding.Namespace) { OpenTimeout = binding.OpenTimeout; CloseTimeout = binding.CloseTimeout; SendTimeout = binding.SendTimeout; ReceiveTimeout = binding.ReceiveTimeout; scheme = binding.Scheme; security = binding as ISecurityCapabilities; }
private SecurityStandardsManager GetConfiguredSecurityStandardsManager(Binding binding) { if (binding == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("binding"); } SecurityBindingElement element = binding.CreateBindingElements().Find<SecurityBindingElement>(); if (element == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("binding", System.ServiceModel.SR.GetString("NoSecurityBindingElementFound")); } return new SecurityStandardsManager(element.MessageSecurityVersion, new WSSecurityTokenSerializer(element.MessageSecurityVersion.SecurityVersion)); }
private bool IsSecureConversationBinding(Binding binding) { if (binding == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("binding"); } SecurityBindingElement sbe = binding.CreateBindingElements().Find<SecurityBindingElement>(); if (sbe != null) { foreach (SecurityTokenParameters parameters in new System.ServiceModel.Security.SecurityTokenParametersEnumerable(sbe, true)) { if (parameters is SecureConversationSecurityTokenParameters) { return true; } } } return false; }
internal static bool IsTransactedReceive(Binding binding, BindingParameterCollection bindingParameters) { // New school ITransactedBindingElement transactedBindingElement = binding.GetProperty<ITransactedBindingElement>(bindingParameters); if (transactedBindingElement != null) { return transactedBindingElement.TransactedReceiveEnabled; } // Old School foreach (BindingElement element in binding.CreateBindingElements()) { transactedBindingElement = element as ITransactedBindingElement; if (transactedBindingElement != null && transactedBindingElement.TransactedReceiveEnabled) { return true; } } return false; }
private SecurityKeyEntropyMode GetIssuerBindingKeyEntropyModeOrDefault(Binding issuerBinding) { SecurityBindingElement element = issuerBinding.CreateBindingElements().Find<SecurityBindingElement>(); if (element != null) { return element.KeyEntropyMode; } return this.parent.IssuedToken.DefaultKeyEntropyMode; }
static CustomBinding CreateBinding (Binding source) { var bec = source.CreateBindingElements (); bec.Insert (0, new DiscoveryClientBindingElement ()); return new CustomBinding (bec); }
static BindingElementCollection GetBindingElements(WsdlEndpointConversionContext context) { Binding binding = context.Endpoint.Binding; BindingElementCollection elements = binding is CustomBinding ? ((CustomBinding)binding).Elements : binding.CreateBindingElements(); return(elements); }
public static ServiceChannelFactory BuildChannelFactory(ServiceEndpoint serviceEndpoint, bool useActiveAutoClose) { if (serviceEndpoint == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("serviceEndpoint"); } serviceEndpoint.EnsureInvariants(); serviceEndpoint.ValidateForClient(); ChannelRequirements requirements; ContractDescription contractDescription = serviceEndpoint.Contract; ChannelRequirements.ComputeContractRequirements(contractDescription, out requirements); BindingParameterCollection parameters; ClientRuntime clientRuntime = DispatcherBuilder.BuildProxyBehavior(serviceEndpoint, out parameters); Binding binding = serviceEndpoint.Binding; Type[] requiredChannels = ChannelRequirements.ComputeRequiredChannels(ref requirements); CustomBinding customBinding = new CustomBinding(binding); BindingContext context = new BindingContext(customBinding, parameters); InternalDuplexBindingElement internalDuplexBindingElement = null; InternalDuplexBindingElement.AddDuplexFactorySupport(context, ref internalDuplexBindingElement); customBinding = new CustomBinding(context.RemainingBindingElements); customBinding.CopyTimeouts(serviceEndpoint.Binding); foreach (Type type in requiredChannels) { if (type == typeof(IOutputChannel) && customBinding.CanBuildChannelFactory <IOutputChannel>(parameters)) { return(new ServiceChannelFactoryOverOutput(customBinding.BuildChannelFactory <IOutputChannel>(parameters), clientRuntime, binding)); } if (type == typeof(IRequestChannel) && customBinding.CanBuildChannelFactory <IRequestChannel>(parameters)) { return(new ServiceChannelFactoryOverRequest(customBinding.BuildChannelFactory <IRequestChannel>(parameters), clientRuntime, binding)); } if (type == typeof(IDuplexChannel) && customBinding.CanBuildChannelFactory <IDuplexChannel>(parameters)) { if (requirements.usesReply && binding.CreateBindingElements().Find <TransportBindingElement>().ManualAddressing) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException( SR.GetString(SR.CantCreateChannelWithManualAddressing))); } return(new ServiceChannelFactoryOverDuplex(customBinding.BuildChannelFactory <IDuplexChannel>(parameters), clientRuntime, binding)); } if (type == typeof(IOutputSessionChannel) && customBinding.CanBuildChannelFactory <IOutputSessionChannel>(parameters)) { return(new ServiceChannelFactoryOverOutputSession(customBinding.BuildChannelFactory <IOutputSessionChannel>(parameters), clientRuntime, binding, false)); } if (type == typeof(IRequestSessionChannel) && customBinding.CanBuildChannelFactory <IRequestSessionChannel>(parameters)) { return(new ServiceChannelFactoryOverRequestSession(customBinding.BuildChannelFactory <IRequestSessionChannel>(parameters), clientRuntime, binding, false)); } if (type == typeof(IDuplexSessionChannel) && customBinding.CanBuildChannelFactory <IDuplexSessionChannel>(parameters)) { if (requirements.usesReply && binding.CreateBindingElements().Find <TransportBindingElement>().ManualAddressing) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException( SR.GetString(SR.CantCreateChannelWithManualAddressing))); } return(new ServiceChannelFactoryOverDuplexSession(customBinding.BuildChannelFactory <IDuplexSessionChannel>(parameters), clientRuntime, binding, useActiveAutoClose)); } } foreach (Type type in requiredChannels) { // For SessionMode.Allowed or SessionMode.NotAllowed we will accept session-ful variants as well if (type == typeof(IOutputChannel) && customBinding.CanBuildChannelFactory <IOutputSessionChannel>(parameters)) { return(new ServiceChannelFactoryOverOutputSession(customBinding.BuildChannelFactory <IOutputSessionChannel>(parameters), clientRuntime, binding, true)); } if (type == typeof(IRequestChannel) && customBinding.CanBuildChannelFactory <IRequestSessionChannel>(parameters)) { return(new ServiceChannelFactoryOverRequestSession(customBinding.BuildChannelFactory <IRequestSessionChannel>(parameters), clientRuntime, binding, true)); } // and for SessionMode.Required, it is possible that the InstanceContextProvider is handling the session management, so // accept datagram variants if that is the case if (type == typeof(IRequestSessionChannel) && customBinding.CanBuildChannelFactory <IRequestChannel>(parameters) && customBinding.GetProperty <IContextSessionProvider>(parameters) != null) { return(new ServiceChannelFactoryOverRequest(customBinding.BuildChannelFactory <IRequestChannel>(parameters), clientRuntime, binding)); } } // we put a lot of work into creating a good error message, as this is a common case Dictionary <Type, byte> supportedChannels = new Dictionary <Type, byte>(); if (customBinding.CanBuildChannelFactory <IOutputChannel>(parameters)) { supportedChannels.Add(typeof(IOutputChannel), 0); } if (customBinding.CanBuildChannelFactory <IRequestChannel>(parameters)) { supportedChannels.Add(typeof(IRequestChannel), 0); } if (customBinding.CanBuildChannelFactory <IDuplexChannel>(parameters)) { supportedChannels.Add(typeof(IDuplexChannel), 0); } if (customBinding.CanBuildChannelFactory <IOutputSessionChannel>(parameters)) { supportedChannels.Add(typeof(IOutputSessionChannel), 0); } if (customBinding.CanBuildChannelFactory <IRequestSessionChannel>(parameters)) { supportedChannels.Add(typeof(IRequestSessionChannel), 0); } if (customBinding.CanBuildChannelFactory <IDuplexSessionChannel>(parameters)) { supportedChannels.Add(typeof(IDuplexSessionChannel), 0); } throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(ChannelRequirements.CantCreateChannelException( supportedChannels.Keys, requiredChannels, binding.Name)); }
bool IsSecureConversationBinding(Binding binding) { if (binding == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("binding"); SecurityBindingElement securityBindingElement = binding.CreateBindingElements().Find<SecurityBindingElement>(); if (securityBindingElement == null) { return false; } foreach (SecurityTokenParameters tokenParam in new SecurityTokenParametersEnumerable(securityBindingElement, true)) { if (tokenParam is SecureConversationSecurityTokenParameters) { return true; } } return false; }
public CustomBinding Extend(Binding binding) { BindingElementCollection bindingElements = binding.CreateBindingElements(); return new CustomBinding(this.Extend(bindingElements)); }
SecurityKeyEntropyMode GetIssuerBindingKeyEntropyModeOrDefault(Binding issuerBinding) { BindingElementCollection bindingElements = issuerBinding.CreateBindingElements(); SecurityBindingElement securityBindingElement = bindingElements.Find<SecurityBindingElement>(); if (securityBindingElement != null) { return securityBindingElement.KeyEntropyMode; } else { return parent.IssuedToken.DefaultKeyEntropyMode; } }
private void GetIssuerBindingSecurityVersion(Binding issuerBinding, MessageSecurityVersion issuedTokenParametersDefaultMessageSecurityVersion, SecurityBindingElement outerSecurityBindingElement, out MessageSecurityVersion messageSecurityVersion, out SecurityTokenSerializer tokenSerializer) { messageSecurityVersion = null; if (issuerBinding != null) { SecurityBindingElement element = issuerBinding.CreateBindingElements().Find<SecurityBindingElement>(); if (element != null) { messageSecurityVersion = element.MessageSecurityVersion; } } if (messageSecurityVersion == null) { if (issuedTokenParametersDefaultMessageSecurityVersion != null) { messageSecurityVersion = issuedTokenParametersDefaultMessageSecurityVersion; } else if (outerSecurityBindingElement != null) { messageSecurityVersion = outerSecurityBindingElement.MessageSecurityVersion; } } if (messageSecurityVersion == null) { messageSecurityVersion = MessageSecurityVersion.Default; } tokenSerializer = this.CreateSecurityTokenSerializer(messageSecurityVersion.SecurityTokenVersion); }
private void Initialize(EndpointAddress address, Binding binding, ServiceCredentials credentials) { if (address == null) throw new ArgumentNullException("address"); if (credentials == null) throw new ArgumentNullException("credentials"); if (binding == null) throw new ArgumentNullException("binding"); BindingElementCollection elements = binding.CreateBindingElements(); SslStreamSecurityBindingElement element = elements.Find<SslStreamSecurityBindingElement>(); if (element != null) { element.IdentityVerifier = new SWIdentityVerifier(); CustomBinding newbinding = new CustomBinding(elements); // Transfer timeout settings from the old binding to the new newbinding.CloseTimeout = binding.CloseTimeout; newbinding.OpenTimeout = binding.OpenTimeout; newbinding.ReceiveTimeout = binding.ReceiveTimeout; newbinding.SendTimeout = binding.SendTimeout; binding = newbinding; } _channelFactory = CreateChannelFactory(binding, address); credentials.ApplyTo(_channelFactory); CorrectChannelFactory(); }
public static ServiceChannelFactory BuildChannelFactory(ServiceEndpoint serviceEndpoint, bool useActiveAutoClose) { ChannelRequirements requirements; BindingParameterCollection parameters; if (serviceEndpoint == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("serviceEndpoint"); } serviceEndpoint.EnsureInvariants(); serviceEndpoint.ValidateForClient(); ChannelRequirements.ComputeContractRequirements(serviceEndpoint.Contract, out requirements); System.ServiceModel.Dispatcher.ClientRuntime clientRuntime = DispatcherBuilder.BuildProxyBehavior(serviceEndpoint, out parameters); Binding binding = serviceEndpoint.Binding; System.Type[] requiredChannels = ChannelRequirements.ComputeRequiredChannels(ref requirements); CustomBinding binding2 = new CustomBinding(binding); BindingContext context = new BindingContext(binding2, parameters); InternalDuplexBindingElement internalDuplexBindingElement = null; InternalDuplexBindingElement.AddDuplexFactorySupport(context, ref internalDuplexBindingElement); binding2 = new CustomBinding(context.RemainingBindingElements); binding2.CopyTimeouts(serviceEndpoint.Binding); foreach (System.Type type in requiredChannels) { if ((type == typeof(IOutputChannel)) && binding2.CanBuildChannelFactory <IOutputChannel>(parameters)) { return(new ServiceChannelFactoryOverOutput(binding2.BuildChannelFactory <IOutputChannel>(parameters), clientRuntime, binding)); } if ((type == typeof(IRequestChannel)) && binding2.CanBuildChannelFactory <IRequestChannel>(parameters)) { return(new ServiceChannelFactoryOverRequest(binding2.BuildChannelFactory <IRequestChannel>(parameters), clientRuntime, binding)); } if ((type == typeof(IDuplexChannel)) && binding2.CanBuildChannelFactory <IDuplexChannel>(parameters)) { if (requirements.usesReply && binding.CreateBindingElements().Find <TransportBindingElement>().ManualAddressing) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("CantCreateChannelWithManualAddressing"))); } return(new ServiceChannelFactoryOverDuplex(binding2.BuildChannelFactory <IDuplexChannel>(parameters), clientRuntime, binding)); } if ((type == typeof(IOutputSessionChannel)) && binding2.CanBuildChannelFactory <IOutputSessionChannel>(parameters)) { return(new ServiceChannelFactoryOverOutputSession(binding2.BuildChannelFactory <IOutputSessionChannel>(parameters), clientRuntime, binding, false)); } if ((type == typeof(IRequestSessionChannel)) && binding2.CanBuildChannelFactory <IRequestSessionChannel>(parameters)) { return(new ServiceChannelFactoryOverRequestSession(binding2.BuildChannelFactory <IRequestSessionChannel>(parameters), clientRuntime, binding, false)); } if ((type == typeof(IDuplexSessionChannel)) && binding2.CanBuildChannelFactory <IDuplexSessionChannel>(parameters)) { if (requirements.usesReply && binding.CreateBindingElements().Find <TransportBindingElement>().ManualAddressing) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("CantCreateChannelWithManualAddressing"))); } return(new ServiceChannelFactoryOverDuplexSession(binding2.BuildChannelFactory <IDuplexSessionChannel>(parameters), clientRuntime, binding, useActiveAutoClose)); } } foreach (System.Type type2 in requiredChannels) { if ((type2 == typeof(IOutputChannel)) && binding2.CanBuildChannelFactory <IOutputSessionChannel>(parameters)) { return(new ServiceChannelFactoryOverOutputSession(binding2.BuildChannelFactory <IOutputSessionChannel>(parameters), clientRuntime, binding, true)); } if ((type2 == typeof(IRequestChannel)) && binding2.CanBuildChannelFactory <IRequestSessionChannel>(parameters)) { return(new ServiceChannelFactoryOverRequestSession(binding2.BuildChannelFactory <IRequestSessionChannel>(parameters), clientRuntime, binding, true)); } if (((type2 == typeof(IRequestSessionChannel)) && binding2.CanBuildChannelFactory <IRequestChannel>(parameters)) && (binding2.GetProperty <IContextSessionProvider>(parameters) != null)) { return(new ServiceChannelFactoryOverRequest(binding2.BuildChannelFactory <IRequestChannel>(parameters), clientRuntime, binding)); } } Dictionary <System.Type, byte> dictionary = new Dictionary <System.Type, byte>(); if (binding2.CanBuildChannelFactory <IOutputChannel>(parameters)) { dictionary.Add(typeof(IOutputChannel), 0); } if (binding2.CanBuildChannelFactory <IRequestChannel>(parameters)) { dictionary.Add(typeof(IRequestChannel), 0); } if (binding2.CanBuildChannelFactory <IDuplexChannel>(parameters)) { dictionary.Add(typeof(IDuplexChannel), 0); } if (binding2.CanBuildChannelFactory <IOutputSessionChannel>(parameters)) { dictionary.Add(typeof(IOutputSessionChannel), 0); } if (binding2.CanBuildChannelFactory <IRequestSessionChannel>(parameters)) { dictionary.Add(typeof(IRequestSessionChannel), 0); } if (binding2.CanBuildChannelFactory <IDuplexSessionChannel>(parameters)) { dictionary.Add(typeof(IDuplexSessionChannel), 0); } throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(ChannelRequirements.CantCreateChannelException(dictionary.Keys, requiredChannels, binding.Name)); }
void GetIssuerBindingSecurityVersion(Binding issuerBinding, MessageSecurityVersion issuedTokenParametersDefaultMessageSecurityVersion, SecurityBindingElement outerSecurityBindingElement, out MessageSecurityVersion messageSecurityVersion, out SecurityTokenSerializer tokenSerializer) { // Logic for setting version is: // 1. use issuer SBE // 2. use ITSP // 3. use outer SBE // messageSecurityVersion = null; if (issuerBinding != null) { BindingElementCollection bindingElements = issuerBinding.CreateBindingElements(); SecurityBindingElement securityBindingElement = bindingElements.Find<SecurityBindingElement>(); if (securityBindingElement != null) { messageSecurityVersion = securityBindingElement.MessageSecurityVersion; } } if (messageSecurityVersion == null) { if (issuedTokenParametersDefaultMessageSecurityVersion != null) { messageSecurityVersion = issuedTokenParametersDefaultMessageSecurityVersion; } else if (outerSecurityBindingElement != null) { messageSecurityVersion = outerSecurityBindingElement.MessageSecurityVersion; } } if (messageSecurityVersion == null) { messageSecurityVersion = MessageSecurityVersion.Default; } tokenSerializer = this.CreateSecurityTokenSerializer(messageSecurityVersion.SecurityTokenVersion); }
private bool IsManualAddressing(Binding binding) { TransportBindingElement transport = binding.CreateBindingElements().Find<TransportBindingElement>(); if (transport == null) { string text = SR.Format(SR.SFxBindingMustContainTransport2, binding.Name, binding.Namespace); Exception error = new InvalidOperationException(text); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(error); } return transport.ManualAddressing; }
private bool IsManualAddressing(Binding binding) { TransportBindingElement element = binding.CreateBindingElements().Find<TransportBindingElement>(); if (element == null) { Exception exception = new InvalidOperationException(System.ServiceModel.SR.GetString("SFxBindingMustContainTransport2", new object[] { binding.Name, binding.Namespace })); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(exception); } return element.ManualAddressing; }