public OperationContext(IContextChannel channel) { if (channel == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("channel")); } ServiceChannel serviceChannel = channel as ServiceChannel; //Could be a TransparentProxy if (serviceChannel == null) { serviceChannel = ServiceChannelFactory.GetServiceChannel(channel); } if (serviceChannel != null) { this.outgoingMessageVersion = serviceChannel.MessageVersion; this.channel = serviceChannel; } else { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SFxInvalidChannelToOperationContext))); } }
protected TResult UsingService <TResult>(Func <ISearchService, TResult> action, bool close = false) { try { var channel = ServiceChannelFactory.CreateChannel(ServiceEndpointAddress); try { return(action(channel)); } finally { if (close) { try { ((IClientChannel)channel).Close(); } catch { ((IClientChannel)channel).Abort(); } } } } catch (Exception e) { ADXTrace.Instance.TraceError(TraceCategory.Application, string.Format("Service exception: {0}", e.ToString())); throw; } }
internal void BeforeSendRequest(ref ProxyRpc rpc) { int offset = this.MessageInspectorCorrelationOffset; try { for (int i = 0; i < _messageInspectors.Length; i++) { ServiceChannel clientChannel = ServiceChannelFactory.GetServiceChannel(rpc.Channel.Proxy); rpc.Correlation[offset + i] = _messageInspectors[i].BeforeSendRequest(ref rpc.Request, clientChannel); if (WcfEventSource.Instance.ClientMessageInspectorBeforeSendInvokedIsEnabled()) { WcfEventSource.Instance.ClientMessageInspectorBeforeSendInvoked(rpc.EventTraceActivity, _messageInspectors[i].GetType().FullName); } } } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } if (ErrorBehavior.ShouldRethrowClientSideExceptionAsIs(e)) { throw; } throw DiagnosticUtility.ExceptionUtility.ThrowHelperCallback(e); } }
public static async Task <bool> InitializeAsFirstInstance(string uniqueName, string[] args) { _singleInstanceMutex = new Mutex(true, uniqueName, out bool firstInstance); try { if (firstInstance) { _host = new InprocHostFactory().Create <ApplicationProxy>("T4VPN-app/initialization"); _host.Open(TimeSpan.FromSeconds(10)); } else { using var channel = new ServiceChannelFactory().Create <IApplicationProxy>("T4VPN-app/initialization"); await channel.Proxy.InvokeRunningInstance(args); } } catch (CommunicationException) { } catch (TimeoutException) { } return(firstInstance); }
public static ShowService CreateSubtitleService() { SubtitlesConfigurationType configuration = new SubtitlesConfigurationType(); configuration.BierdopjeUrl = "http://api.bierdopje.com"; configuration.BierdopjeApiKey = "51AFBB7D64B937E1"; ServiceChannelFactory serviceChannelFactory = new ServiceChannelFactory(configuration); return new ShowService(new SubtitleServiceResponseDeserializer(), serviceChannelFactory); }
internal ServiceChannel GetServiceChannelFromProxy(IContextChannel channel) { if (!(channel is ServiceChannel serviceChannel)) { serviceChannel = ServiceChannelFactory.GetServiceChannel(channel); } return(serviceChannel); }
public VpnService( ServiceChannelFactory channelFactory, VpnEvents vpnEvents, ILogger logger) { _channelFactory = channelFactory; _logger = logger; _vpnEvents = vpnEvents; }
internal DisplayInitializationUIAsyncResult(ServiceChannel channel, IInteractiveChannelInitializer[] initializers, AsyncCallback callback, object state) : base(callback, state) { _channel = channel; _initializers = initializers; _proxy = ServiceChannelFactory.GetServiceChannel(channel.Proxy); this.CallBegin(true); }
internal ServiceChannel GetServiceChannelFromProxy(IContextChannel channel) { ServiceChannel serviceChannel = channel as ServiceChannel; if (serviceChannel == null) { serviceChannel = ServiceChannelFactory.GetServiceChannel(channel); } return(serviceChannel); }
private ServiceChannelFactory CreateServiceChannelFactory() { ServiceChannelFactory factory = ServiceChannelFactory.BuildChannelFactory(this.serviceEndpoint); if (factory == null) { throw Fx.AssertAndThrow("We should get a ServiceChannelFactory back"); } return(factory); }
private ServiceChannelFactory CreateServiceChannelFactory() { this.serviceChannelFactory = ServiceChannelFactory.BuildChannelFactory(this.serviceEndpoint); if (this.serviceChannelFactory == null) { throw Fx.AssertAndThrow("We should get a ServiceChannelFactory back"); } this.FixupProxyBehavior(); return(this.serviceChannelFactory); }
private void FaultInserviceChannelFactory() { if (this.propertyTable == null) { throw Fx.AssertAndThrow("PropertyTable should not be null"); } foreach (IEndpointBehavior behavior in this.behaviors) { this.serviceEndpoint.Behaviors.Add(behavior); } this.serviceChannelFactory = this.CreateServiceChannelFactory(); }
private void FillChannelInfo(IChannel channel, IWmiInstance instance) { instance.SetProperty("Type", channel.GetType().ToString()); ServiceChannel serviceChannel = ServiceChannelFactory.GetServiceChannel(channel); if (serviceChannel != null) { string str = (serviceChannel.RemoteAddress == null) ? string.Empty : serviceChannel.RemoteAddress.ToString(); instance.SetProperty("RemoteAddress", str); string contractName = (serviceChannel.ClientRuntime != null) ? serviceChannel.ClientRuntime.ContractName : string.Empty; string str3 = EndpointInstanceProvider.EndpointReference(str, contractName, false); instance.SetProperty("RemoteEndpoint", str3); instance.SetProperty("LocalAddress", (serviceChannel.LocalAddress == null) ? string.Empty : serviceChannel.LocalAddress.ToString()); instance.SetProperty("SessionId", ((IContextChannel)serviceChannel).SessionId); } }
void FaultInserviceChannelFactory() { if (contractType == null) { throw Fx.AssertAndThrow("contractType should not be null"); } if (serviceEndpoint == null) { serviceEndpoint = CreateServiceEndpoint(); } foreach (IEndpointBehavior behavior in behaviors) { serviceEndpoint.Behaviors.Add(behavior); } serviceChannelFactory = CreateServiceChannelFactory(); }
protected virtual IChannelFactory CreateFactory() { if (this.Endpoint == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxChannelFactoryCannotCreateFactoryWithoutDescription"))); } if (this.Endpoint.Binding != null) { return(ServiceChannelFactory.BuildChannelFactory(this.Endpoint, this.UseActiveAutoClose)); } if (this.configurationName != null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxChannelFactoryNoBindingFoundInConfig1", new object[] { this.configurationName }))); } throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxChannelFactoryNoBindingFoundInConfigOrCode"))); }
private Task InitializeServiceChannel(ServiceChannel channel) { if (_wasChannelThrottled) { // Comment preserved from .NET Framework: // When the idle timeout was hit, the constructor of ServiceChannel will abort itself directly. So // the session throttle will not be released and thus lead to a service unavailablity. // Note that if the channel is already aborted, the next line "channel.ServiceThrottle = this.throttle;" will throw an exception, // so we are not going to do any more work inside this method. // Ideally we should do a thorough refactoring work for this throttling issue. However, it's too risky. We should consider // this in a whole release. // Note that the "wasChannelThrottled" boolean will only be true if we aquired the session throttle. So we don't have to check HasSession // again here. if (channel.Aborted && _throttle != null) { // This line will release the "session" throttle. _throttle.DeactivateChannel(); } channel.ServiceThrottle = _throttle; } if (InstanceContextServiceThrottle != null) { channel.InstanceContextServiceThrottle = InstanceContextServiceThrottle; } ClientRuntime clientRuntime = channel.ClientRuntime; if (clientRuntime != null) { Type contractType = clientRuntime.ContractClientType; Type callbackType = clientRuntime.CallbackClientType; if (contractType != null) { channel.Proxy = ServiceChannelFactory.CreateProxy(contractType, callbackType, MessageDirection.Output, channel); } } if (_serviceDispatcher != null) { _serviceDispatcher.ChannelDispatcher.InitializeChannel((IClientChannel)channel.Proxy); } return(((IChannel)channel).OpenAsync()); }
public virtual TChannel CreateChannel(InstanceContext callbackInstance, EndpointAddress address, Uri via) { if (address == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(address)); } if (CallbackType != null && callbackInstance == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.SFxCreateDuplexChannelNoCallback1)); } if (callbackInstance == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.SFxCreateDuplexChannelNoCallback)); } if (callbackInstance.UserObject == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.SFxCreateDuplexChannelNoCallbackUserObject)); } if (!HasDuplexOperations()) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.SFxCreateDuplexChannel1, Endpoint.Contract.Name))); } Type userObjectType = callbackInstance.UserObject.GetType(); Type callbackType = Endpoint.Contract.CallbackContractType; if (callbackType != null && !callbackType.IsAssignableFrom(userObjectType)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format( SR.SFxCreateDuplexChannelBadCallbackUserObject, callbackType))); } EnsureOpened(); TChannel result = ServiceChannelFactory.CreateChannel <TChannel>(address, via); // Desktop: this.ServiceChannelFactory.CreateChannel(typeof(TChannel), address, via); IDuplexContextChannel duplexChannel = result as IDuplexContextChannel; if (duplexChannel != null) { duplexChannel.CallbackInstance = callbackInstance; } return(result); }
public OperationContext(IContextChannel channel) { if (channel == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("channel")); } ServiceChannel serviceChannel = channel as ServiceChannel; if (serviceChannel == null) { serviceChannel = ServiceChannelFactory.GetServiceChannel(channel); } if (serviceChannel == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxInvalidChannelToOperationContext"))); } this.outgoingMessageVersion = serviceChannel.MessageVersion; this.channel = serviceChannel; }
void FillChannelInfo(IChannel channel, IWmiInstance instance) { Fx.Assert(null != instance, ""); Fx.Assert(null != channel, ""); instance.SetProperty(AdministrationStrings.Type, channel.GetType().ToString()); ServiceChannel serviceChannel = ServiceChannelFactory.GetServiceChannel(channel); if (null != serviceChannel) { string uri = serviceChannel.RemoteAddress == null ? String.Empty : serviceChannel.RemoteAddress.ToString(); instance.SetProperty(AdministrationStrings.RemoteAddress, uri); string contractName = null != serviceChannel.ClientRuntime ? serviceChannel.ClientRuntime.ContractName : String.Empty; string remoteEndpoint = EndpointInstanceProvider.EndpointReference(uri, contractName, false); instance.SetProperty(AdministrationStrings.RemoteEndpoint, remoteEndpoint); instance.SetProperty(AdministrationStrings.LocalAddress, serviceChannel.LocalAddress == null ? String.Empty : serviceChannel.LocalAddress.ToString()); instance.SetProperty(AdministrationStrings.SessionId, ((IContextChannel)serviceChannel).SessionId); } }
protected virtual IChannelFactory CreateFactory() { if (this.Endpoint == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.SFxChannelFactoryCannotCreateFactoryWithoutDescription)); } if (this.Endpoint.Binding == null) { if (_configurationName != null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.SFxChannelFactoryNoBindingFoundInConfig1, _configurationName))); } else { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.SFxChannelFactoryNoBindingFoundInConfigOrCode)); } } return(ServiceChannelFactory.BuildChannelFactory(this.Endpoint, this.UseActiveAutoClose)); }
private void InitializeServiceChannel(ServiceChannel channel) { ClientRuntime clientRuntime = channel.ClientRuntime; if (clientRuntime != null) { Type contractType = clientRuntime.ContractClientType; Type callbackType = clientRuntime.CallbackClientType; if (contractType != null) { channel.Proxy = ServiceChannelFactory.CreateProxy(contractType, callbackType, MessageDirection.Output, channel); } } if (_listener != null) { _listener.ChannelDispatcher.InitializeChannel((IClientChannel)channel.Proxy); } ((IChannel)channel).Open(); }
void SetupRstChannelFactory() { IChannelFactory <IRequestChannel> innerChannelFactory = null; ChannelBuilder channelBuilder = new ChannelBuilder(this.IssuerBindingContext.Clone(), true); // if the underlying transport does not support request/reply, wrap it inside // a service channel factory. if (channelBuilder.CanBuildChannelFactory <IRequestChannel>()) { innerChannelFactory = channelBuilder.BuildChannelFactory <IRequestChannel>(); this.requiresManualReplyAddressing = true; } else { ClientRuntime clientRuntime = new ClientRuntime("RequestSecurityTokenContract", NamingHelper.DefaultNamespace); clientRuntime.ValidateMustUnderstand = false; ServiceChannelFactory serviceChannelFactory = ServiceChannelFactory.BuildChannelFactory(channelBuilder, clientRuntime); serviceChannelFactory.ClientRuntime.UseSynchronizationContext = false; serviceChannelFactory.ClientRuntime.AddTransactionFlowProperties = false; ClientOperation rstOperation = new ClientOperation(serviceChannelFactory.ClientRuntime, "RequestSecurityToken", this.RequestSecurityTokenAction.Value); rstOperation.Formatter = MessageOperationFormatter.Instance; serviceChannelFactory.ClientRuntime.Operations.Add(rstOperation); if (this.IsMultiLegNegotiation) { ClientOperation rstrOperation = new ClientOperation(serviceChannelFactory.ClientRuntime, "RequestSecurityTokenResponse", this.RequestSecurityTokenResponseAction.Value); rstrOperation.Formatter = MessageOperationFormatter.Instance; serviceChannelFactory.ClientRuntime.Operations.Add(rstrOperation); } // service channel automatically adds reply headers this.requiresManualReplyAddressing = false; innerChannelFactory = new SecuritySessionSecurityTokenProvider.RequestChannelFactory(serviceChannelFactory); } this.rstChannelFactory = GetNegotiationChannelFactory(innerChannelFactory, channelBuilder); this.messageVersion = channelBuilder.Binding.MessageVersion; }
private void SetupRstChannelFactory() { IChannelFactory <IRequestChannel> transportChannelFactory = null; ChannelBuilder channelBuilder = new ChannelBuilder(this.IssuerBindingContext.Clone(), true); if (channelBuilder.CanBuildChannelFactory <IRequestChannel>()) { transportChannelFactory = channelBuilder.BuildChannelFactory <IRequestChannel>(); this.requiresManualReplyAddressing = true; } else { ClientRuntime clientRuntime = new ClientRuntime("RequestSecurityTokenContract", "http://tempuri.org/") { ValidateMustUnderstand = false }; ServiceChannelFactory serviceChannelFactory = ServiceChannelFactory.BuildChannelFactory(channelBuilder, clientRuntime); serviceChannelFactory.ClientRuntime.UseSynchronizationContext = false; serviceChannelFactory.ClientRuntime.AddTransactionFlowProperties = false; ClientOperation item = new ClientOperation(serviceChannelFactory.ClientRuntime, "RequestSecurityToken", this.RequestSecurityTokenAction.Value) { Formatter = MessageOperationFormatter.Instance }; serviceChannelFactory.ClientRuntime.Operations.Add(item); if (this.IsMultiLegNegotiation) { ClientOperation operation2 = new ClientOperation(serviceChannelFactory.ClientRuntime, "RequestSecurityTokenResponse", this.RequestSecurityTokenResponseAction.Value) { Formatter = MessageOperationFormatter.Instance }; serviceChannelFactory.ClientRuntime.Operations.Add(operation2); } this.requiresManualReplyAddressing = false; transportChannelFactory = new SecuritySessionSecurityTokenProvider.RequestChannelFactory(serviceChannelFactory); } this.rstChannelFactory = this.GetNegotiationChannelFactory(transportChannelFactory, channelBuilder); this.messageVersion = channelBuilder.Binding.MessageVersion; }
public OperationContext(IContextChannel channel) { if (channel == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(channel)); } //Could be a TransparentProxy if (!(channel is ServiceChannel serviceChannel)) { serviceChannel = ServiceChannelFactory.GetServiceChannel(channel); } if (serviceChannel != null) { OutgoingMessageVersion = serviceChannel.MessageVersion; InternalServiceChannel = serviceChannel; } else { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.SFxInvalidChannelToOperationContext)); } }
internal ShowService(SubtitleServiceResponseDeserializer responseParser, ServiceChannelFactory serviceChannelFactory) { this.responseParser = responseParser; this.serviceChannelFactory = serviceChannelFactory; }
private ServiceChannelFactory CreateServiceChannelFactory() { serviceChannelFactory = ServiceChannelFactory.BuildChannelFactory(serviceEndpoint) as ServiceChannelFactory; if (serviceChannelFactory == null) { throw Fx.AssertAndThrow("We should get a ServiceChannelFactory back"); } FixupProxyBehavior(); return serviceChannelFactory; }
public ServiceClient(ILogger logger, ServiceChannelFactory channelFactory, UpdateEvents updateEvents) { _channelFactory = channelFactory; _logger = logger; _updateEvents = updateEvents; }
void FaultInserviceChannelFactory() { if (contractType == null) { throw Fx.AssertAndThrow("contractType should not be null"); } if (serviceEndpoint == null) { serviceEndpoint = CreateServiceEndpoint(); } foreach (IEndpointBehavior behavior in behaviors) serviceEndpoint.Behaviors.Add(behavior); serviceChannelFactory = CreateServiceChannelFactory(); }
void FaultInserviceChannelFactory() { if (propertyTable == null) { throw Fx.AssertAndThrow("PropertyTable should not be null"); } foreach (IEndpointBehavior behavior in behaviors) serviceEndpoint.Behaviors.Add(behavior); serviceChannelFactory = CreateServiceChannelFactory(); }
public RequestChannelFactory(ServiceChannelFactory serviceChannelFactory) { this.serviceChannelFactory = serviceChannelFactory; }
/// <summary> /// Creates a <see cref="ServiceConsumer" /> from a factory method that returns a communication object / channel / Visual Studio Service Reference ServiceClient. /// </summary> /// <typeparam name="TServiceInterface">The type of the service interface.</typeparam> /// <param name="endpointConfigurationName">Name of the endpoint configuration.</param> /// <param name="retryPolicy">The retry policy.</param> /// <returns> /// A <see cref="ServiceConsumer" />. /// </returns> public static IServiceConsumer <TServiceInterface> Create <TServiceInterface>(string endpointConfigurationName, IRetryPolicyFunction retryPolicy) { Func <ICommunicationObject> factoryMethod = () => ServiceChannelFactory.CreateChannel <TServiceInterface>(endpointConfigurationName); return(ServiceConsumerFactory.Create <TServiceInterface>(factoryMethod, retryPolicy)); }
private void InitializeFactories() { ISecurityCapabilities securityCapabilities = BootstrapSecurityBindingElement.GetProperty <ISecurityCapabilities>(IssuerBindingContext); SecurityCredentialsManager securityCredentials = IssuerBindingContext.BindingParameters.Find <SecurityCredentialsManager>(); if (securityCredentials == null) { securityCredentials = ClientCredentials.CreateDefaultCredentials(); } BindingContext context = IssuerBindingContext; _bootstrapSecurityBindingElement.ReaderQuotas = context.GetInnerProperty <XmlDictionaryReaderQuotas>(); if (_bootstrapSecurityBindingElement.ReaderQuotas == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.EncodingBindingElementDoesNotHandleReaderQuotas)); } TransportBindingElement transportBindingElement = context.RemainingBindingElements.Find <TransportBindingElement>(); if (transportBindingElement != null) { _bootstrapSecurityBindingElement.MaxReceivedMessageSize = transportBindingElement.MaxReceivedMessageSize; } SecurityProtocolFactory securityProtocolFactory = BootstrapSecurityBindingElement.CreateSecurityProtocolFactory <IRequestChannel>(IssuerBindingContext.Clone(), securityCredentials, false, IssuerBindingContext.Clone()); if (_localAddress != null) { MessageFilter issueAndRenewFilter = new SessionActionFilter(_standardsManager, IssueResponseAction.Value, RenewResponseAction.Value); context.BindingParameters.Add(new LocalAddressProvider(_localAddress, issueAndRenewFilter)); } ChannelBuilder channelBuilder = new ChannelBuilder(context, true); IChannelFactory innerChannelFactory; // if the underlying transport does not support request/reply, wrap it inside // a service channel factory. if (channelBuilder.CanBuildChannelFactory <IRequestChannel>()) { innerChannelFactory = channelBuilder.BuildChannelFactory <IRequestChannel>(); _requiresManualReplyAddressing = true; } else { ClientRuntime clientRuntime = new ClientRuntime("RequestSecuritySession", NamingHelper.DefaultNamespace); clientRuntime.UseSynchronizationContext = false; clientRuntime.AddTransactionFlowProperties = false; clientRuntime.ValidateMustUnderstand = false; ServiceChannelFactory serviceChannelFactory = ServiceChannelFactory.BuildChannelFactory(channelBuilder, clientRuntime); ClientOperation issueOperation = new ClientOperation(serviceChannelFactory.ClientRuntime, "Issue", IssueAction.Value); issueOperation.Formatter = s_operationFormatter; serviceChannelFactory.ClientRuntime.Operations.Add(issueOperation); ClientOperation renewOperation = new ClientOperation(serviceChannelFactory.ClientRuntime, "Renew", RenewAction.Value); renewOperation.Formatter = s_operationFormatter; serviceChannelFactory.ClientRuntime.Operations.Add(renewOperation); innerChannelFactory = new RequestChannelFactory(serviceChannelFactory); _requiresManualReplyAddressing = false; } SecurityChannelFactory <IAsyncRequestChannel> securityChannelFactory = new SecurityChannelFactory <IAsyncRequestChannel>( securityCapabilities, IssuerBindingContext, channelBuilder, securityProtocolFactory, innerChannelFactory); // attach the ExtendedProtectionPolicy to the securityProtcolFactory so it will be // available when building the channel. if (transportBindingElement != null) { if (securityChannelFactory.SecurityProtocolFactory != null) { securityChannelFactory.SecurityProtocolFactory.ExtendedProtectionPolicy = transportBindingElement.GetProperty <ExtendedProtectionPolicy>(context); } } _rstChannelFactory = securityChannelFactory; MessageVersion = securityChannelFactory.MessageVersion; }
private void InitializeFactories() { IChannelFactory <IRequestChannel> factory3; ISecurityCapabilities property = this.BootstrapSecurityBindingElement.GetProperty <ISecurityCapabilities>(this.IssuerBindingContext); SecurityCredentialsManager credentialsManager = this.IssuerBindingContext.BindingParameters.Find <SecurityCredentialsManager>(); if (credentialsManager == null) { credentialsManager = ClientCredentials.CreateDefaultCredentials(); } BindingContext issuerBindingContext = this.IssuerBindingContext; this.bootstrapSecurityBindingElement.ReaderQuotas = issuerBindingContext.GetInnerProperty <XmlDictionaryReaderQuotas>(); if (this.bootstrapSecurityBindingElement.ReaderQuotas == null) { throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("EncodingBindingElementDoesNotHandleReaderQuotas"))); } TransportBindingElement element = issuerBindingContext.RemainingBindingElements.Find <TransportBindingElement>(); if (element != null) { this.bootstrapSecurityBindingElement.MaxReceivedMessageSize = element.MaxReceivedMessageSize; } SecurityProtocolFactory protocolFactory = this.BootstrapSecurityBindingElement.CreateSecurityProtocolFactory <IRequestChannel>(this.IssuerBindingContext.Clone(), credentialsManager, false, this.IssuerBindingContext.Clone()); if (protocolFactory is MessageSecurityProtocolFactory) { MessageSecurityProtocolFactory factory2 = protocolFactory as MessageSecurityProtocolFactory; factory2.ApplyConfidentiality = factory2.ApplyIntegrity = factory2.RequireConfidentiality = factory2.RequireIntegrity = true; factory2.ProtectionRequirements.IncomingSignatureParts.ChannelParts.IsBodyIncluded = true; factory2.ProtectionRequirements.OutgoingSignatureParts.ChannelParts.IsBodyIncluded = true; MessagePartSpecification parts = new MessagePartSpecification(true); factory2.ProtectionRequirements.IncomingSignatureParts.AddParts(parts, this.IssueAction); factory2.ProtectionRequirements.IncomingEncryptionParts.AddParts(parts, this.IssueAction); factory2.ProtectionRequirements.IncomingSignatureParts.AddParts(parts, this.RenewAction); factory2.ProtectionRequirements.IncomingEncryptionParts.AddParts(parts, this.RenewAction); factory2.ProtectionRequirements.OutgoingSignatureParts.AddParts(parts, this.IssueResponseAction); factory2.ProtectionRequirements.OutgoingEncryptionParts.AddParts(parts, this.IssueResponseAction); factory2.ProtectionRequirements.OutgoingSignatureParts.AddParts(parts, this.RenewResponseAction); factory2.ProtectionRequirements.OutgoingEncryptionParts.AddParts(parts, this.RenewResponseAction); } protocolFactory.PrivacyNoticeUri = this.PrivacyNoticeUri; protocolFactory.PrivacyNoticeVersion = this.privacyNoticeVersion; if (this.localAddress != null) { MessageFilter filter = new SessionActionFilter(this.standardsManager, new string[] { this.IssueResponseAction.Value, this.RenewResponseAction.Value }); issuerBindingContext.BindingParameters.Add(new LocalAddressProvider(this.localAddress, filter)); } ChannelBuilder channelBuilder = new ChannelBuilder(issuerBindingContext, true); if (channelBuilder.CanBuildChannelFactory <IRequestChannel>()) { factory3 = channelBuilder.BuildChannelFactory <IRequestChannel>(); this.requiresManualReplyAddressing = true; } else { ClientRuntime clientRuntime = new ClientRuntime("RequestSecuritySession", "http://tempuri.org/") { UseSynchronizationContext = false, AddTransactionFlowProperties = false, ValidateMustUnderstand = false }; ServiceChannelFactory serviceChannelFactory = ServiceChannelFactory.BuildChannelFactory(channelBuilder, clientRuntime); ClientOperation item = new ClientOperation(serviceChannelFactory.ClientRuntime, "Issue", this.IssueAction.Value) { Formatter = operationFormatter }; serviceChannelFactory.ClientRuntime.Operations.Add(item); ClientOperation operation2 = new ClientOperation(serviceChannelFactory.ClientRuntime, "Renew", this.RenewAction.Value) { Formatter = operationFormatter }; serviceChannelFactory.ClientRuntime.Operations.Add(operation2); factory3 = new RequestChannelFactory(serviceChannelFactory); this.requiresManualReplyAddressing = false; } SecurityChannelFactory <IRequestChannel> factory5 = new SecurityChannelFactory <IRequestChannel>(property, this.IssuerBindingContext, channelBuilder, protocolFactory, factory3); if ((element != null) && (factory5.SecurityProtocolFactory != null)) { factory5.SecurityProtocolFactory.ExtendedProtectionPolicy = element.GetProperty <ExtendedProtectionPolicy>(issuerBindingContext); } this.rstChannelFactory = factory5; this.messageVersion = factory5.MessageVersion; }
/// <summary> /// Creates a <see cref="ServiceConsumer" /> from a factory method that returns a communication object / channel / Visual Studio Service Reference ServiceClient. /// </summary> /// <typeparam name="TServiceInterface">The type of the service interface.</typeparam> /// <param name="endpointConfigurationName">Name of the endpoint configuration.</param> /// <param name="retryPolicy">The retry policy.</param> /// <param name="exceptionStrategy">The exception strategy.</param> /// <param name="closeTriggerStrategy">The service channel close trigger strategy.</param> /// <returns> /// A <see cref="ServiceConsumer" />. /// </returns> public static IServiceConsumer <TServiceInterface> Create <TServiceInterface>(string endpointConfigurationName, IRetryPolicyFunction retryPolicy, IServiceConsumerExceptionBehaviourStrategy exceptionStrategy, IServiceChannelCloseTriggerStrategy closeTriggerStrategy) { Func <ICommunicationObject> factoryMethod = () => ServiceChannelFactory.CreateChannel <TServiceInterface>(endpointConfigurationName); return(ServiceConsumerFactory.Create <TServiceInterface>(factoryMethod, retryPolicy, exceptionStrategy, closeTriggerStrategy)); }
void InitializeFactories() { ISecurityCapabilities securityCapabilities = this.BootstrapSecurityBindingElement.GetProperty <ISecurityCapabilities>(this.IssuerBindingContext); SecurityCredentialsManager securityCredentials = this.IssuerBindingContext.BindingParameters.Find <SecurityCredentialsManager>(); if (securityCredentials == null) { securityCredentials = ClientCredentials.CreateDefaultCredentials(); } BindingContext context = this.IssuerBindingContext; this.bootstrapSecurityBindingElement.ReaderQuotas = context.GetInnerProperty <XmlDictionaryReaderQuotas>(); if (this.bootstrapSecurityBindingElement.ReaderQuotas == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.EncodingBindingElementDoesNotHandleReaderQuotas))); } TransportBindingElement transportBindingElement = context.RemainingBindingElements.Find <TransportBindingElement>(); if (transportBindingElement != null) { this.bootstrapSecurityBindingElement.MaxReceivedMessageSize = transportBindingElement.MaxReceivedMessageSize; } SecurityProtocolFactory securityProtocolFactory = this.BootstrapSecurityBindingElement.CreateSecurityProtocolFactory <IRequestChannel>(this.IssuerBindingContext.Clone(), securityCredentials, false, this.IssuerBindingContext.Clone()); if (securityProtocolFactory is MessageSecurityProtocolFactory) { MessageSecurityProtocolFactory soapBindingFactory = securityProtocolFactory as MessageSecurityProtocolFactory; soapBindingFactory.ApplyConfidentiality = soapBindingFactory.ApplyIntegrity = soapBindingFactory.RequireConfidentiality = soapBindingFactory.RequireIntegrity = true; soapBindingFactory.ProtectionRequirements.IncomingSignatureParts.ChannelParts.IsBodyIncluded = true; soapBindingFactory.ProtectionRequirements.OutgoingSignatureParts.ChannelParts.IsBodyIncluded = true; MessagePartSpecification bodyPart = new MessagePartSpecification(true); soapBindingFactory.ProtectionRequirements.IncomingSignatureParts.AddParts(bodyPart, IssueAction); soapBindingFactory.ProtectionRequirements.IncomingEncryptionParts.AddParts(bodyPart, IssueAction); soapBindingFactory.ProtectionRequirements.IncomingSignatureParts.AddParts(bodyPart, RenewAction); soapBindingFactory.ProtectionRequirements.IncomingEncryptionParts.AddParts(bodyPart, RenewAction); soapBindingFactory.ProtectionRequirements.OutgoingSignatureParts.AddParts(bodyPart, IssueResponseAction); soapBindingFactory.ProtectionRequirements.OutgoingEncryptionParts.AddParts(bodyPart, IssueResponseAction); soapBindingFactory.ProtectionRequirements.OutgoingSignatureParts.AddParts(bodyPart, RenewResponseAction); soapBindingFactory.ProtectionRequirements.OutgoingEncryptionParts.AddParts(bodyPart, RenewResponseAction); } securityProtocolFactory.PrivacyNoticeUri = this.PrivacyNoticeUri; securityProtocolFactory.PrivacyNoticeVersion = this.privacyNoticeVersion; if (this.localAddress != null) { MessageFilter issueAndRenewFilter = new SessionActionFilter(this.standardsManager, this.IssueResponseAction.Value, this.RenewResponseAction.Value); context.BindingParameters.Add(new LocalAddressProvider(localAddress, issueAndRenewFilter)); } ChannelBuilder channelBuilder = new ChannelBuilder(context, true); IChannelFactory <IRequestChannel> innerChannelFactory; // if the underlying transport does not support request/reply, wrap it inside // a service channel factory. if (channelBuilder.CanBuildChannelFactory <IRequestChannel>()) { innerChannelFactory = channelBuilder.BuildChannelFactory <IRequestChannel>(); requiresManualReplyAddressing = true; } else { ClientRuntime clientRuntime = new ClientRuntime("RequestSecuritySession", NamingHelper.DefaultNamespace); clientRuntime.UseSynchronizationContext = false; clientRuntime.AddTransactionFlowProperties = false; clientRuntime.ValidateMustUnderstand = false; ServiceChannelFactory serviceChannelFactory = ServiceChannelFactory.BuildChannelFactory(channelBuilder, clientRuntime); ClientOperation issueOperation = new ClientOperation(serviceChannelFactory.ClientRuntime, "Issue", IssueAction.Value); issueOperation.Formatter = operationFormatter; serviceChannelFactory.ClientRuntime.Operations.Add(issueOperation); ClientOperation renewOperation = new ClientOperation(serviceChannelFactory.ClientRuntime, "Renew", RenewAction.Value); renewOperation.Formatter = operationFormatter; serviceChannelFactory.ClientRuntime.Operations.Add(renewOperation); innerChannelFactory = new RequestChannelFactory(serviceChannelFactory); requiresManualReplyAddressing = false; } SecurityChannelFactory <IRequestChannel> securityChannelFactory = new SecurityChannelFactory <IRequestChannel>( securityCapabilities, this.IssuerBindingContext, channelBuilder, securityProtocolFactory, innerChannelFactory); // attach the ExtendedProtectionPolicy to the securityProtcolFactory so it will be // available when building the channel. if (transportBindingElement != null) { if (securityChannelFactory.SecurityProtocolFactory != null) { securityChannelFactory.SecurityProtocolFactory.ExtendedProtectionPolicy = transportBindingElement.GetProperty <ExtendedProtectionPolicy>(context); } } this.rstChannelFactory = securityChannelFactory; this.messageVersion = securityChannelFactory.MessageVersion; }