IParagoServiceApplication GetChannel(Uri address, ParagoServiceExecuteOptions options)
        {
            string endpointConfigurationName = GetEndpointConfigurationName(address);

            // Check for a cached channel factory for the endpoint configuration
            if (_channelFactory == null || endpointConfigurationName != _endpointConfigurationName)
            {
                lock (_channelFactoryLock)
                {
                    // Double check to be sure the channel factory will not be created twice
                    if (_channelFactory == null || endpointConfigurationName != _endpointConfigurationName)
                    {
                        // NOTE: It is not thread-safe to dispose the channel factory in use. We let the
                        // GC clean up because changing the endpoint configuration is a rare operation.

                        _channelFactory            = CreateChannelFactory <IParagoServiceApplication>(endpointConfigurationName);
                        _endpointConfigurationName = endpointConfigurationName;
                    }
                }
            }

            if (options == ParagoServiceExecuteOptions.AsProcess)
            {
                return(_channelFactory.CreateChannelAsProcess <IParagoServiceApplication>(new EndpointAddress(address)));
            }
            else
            {
                return(_channelFactory.CreateChannelActingAsLoggedOnUser <IParagoServiceApplication>(new EndpointAddress(address)));
            }
        }
Example #2
0
        /// <summary>
        /// GetChannel method implementation
        /// </summary>
        private IIdentityServiceContract GetChannel(Uri address, ExecuteOptions options)
        {
            string endpointConfigurationName = GetEndpointConfigurationName(address);

            if ((null == m_ChannelFactory) || (endpointConfigurationName != m_EndpointConfigurationName))
            {
                lock (m_ChannelFactoryLock)
                {
                    if ((null == m_ChannelFactory) || (endpointConfigurationName != m_EndpointConfigurationName))
                    {
                        m_ChannelFactory            = CreateChannelFactory <IIdentityServiceContract>(endpointConfigurationName);
                        m_EndpointConfigurationName = endpointConfigurationName;
                    }
                }
            }
            IIdentityServiceContract channel;

            if (ExecuteOptions.AsProcess == (options & ExecuteOptions.AsProcess))
            {
                channel = m_ChannelFactory.CreateChannelAsProcess <IIdentityServiceContract>(new EndpointAddress(address));
            }
            else
            {
                channel = m_ChannelFactory.CreateChannelActingAsLoggedOnUser <IIdentityServiceContract>(new EndpointAddress(address));
            }
            return(channel);
        }
Example #3
0
        /// <summary>
        /// This method gets the end point address to the WCF service. This is where you can support multiple .svc files per service application,
        /// by looking for the default end point name defined in the ServiceApplication class, and swapping it for the EndPoint property that you
        /// set in your Service Client.
        /// </summary>
        /// <param name="loadBalancerContext">The LoadBalancer context obtained from the Service Application proxy</param>
        /// <param name="asProcess">Whether to run as the user or the app pool account.</param>
        /// <typeparam name="TChannel">The type of channel.</typeparam>
        /// <returns>A WCF Communication channel to execute across</returns>
        private TChannel GetChannel <TChannel>(SPServiceLoadBalancerContext loadBalancerContext, bool asProcess)
        {
            TChannel channel = default(TChannel);

            EndpointAddress endPointAddress = new EndpointAddress(new Uri(loadBalancerContext.EndpointAddress.AbsoluteUri.Replace("ReplaceableEndPointName.svc", this.EndPoint)), new AddressHeader[0]);

            string endPointConfigurationName = BaseServiceClient.GetEndpointConfigurationName(endPointAddress.Uri);

            ChannelFactory <TChannel> channelFactory = this.GetChannelFactory <TChannel>(endPointConfigurationName, this.EndPoint);

            if (!asProcess)
            {
                channel = channelFactory.CreateChannelActingAsLoggedOnUser <TChannel>(endPointAddress);
            }
            else
            {
                channel = channelFactory.CreateChannelAsProcess <TChannel>(endPointAddress);
            }

            ((ICommunicationObject)channel).Open();
            return(channel);
        }