Example #1
0
        private static void SetupRemoteOnlyPropogationFilter(IClientChannel channel)
        {
            var remoteOnlyFilter = new RemoteOnlyMessagePropagationFilter();
            var peerNode         = channel.GetProperty <PeerNode>();

            peerNode.MessagePropagationFilter = remoteOnlyFilter;
        }
Example #2
0
        public object BeforeSendRequest(ref Message request, IClientChannel channel)
        {
            // make sure the channel uses the shared cookie container
            channel.GetProperty <IHttpCookieContainerManager>().CookieContainer =
                _factory.CookieContainer;

            request.Headers.Action = RewriteAction(request.Headers.Action);

            // Check for Query Options
            if (OperationContext.Current != null)
            {
                object queryProperty;
                object includeTotalCountProperty;

                OperationContext.Current.OutgoingMessageProperties.TryGetValue(QueryPropertyName, out queryProperty);
                OperationContext.Current.OutgoingMessageProperties.TryGetValue(IncludeTotalCountPropertyName, out includeTotalCountProperty);

                // Add Query Options header if any options were specified
                if (queryProperty != null || includeTotalCountProperty != null)
                {
                    var queryParts        = (queryProperty != null) ? QuerySerializer.Serialize((IQueryable)queryProperty) : null;
                    var includeTotalCount = (bool?)includeTotalCountProperty;

                    // Prepare the request message copy to be modified
                    MessageBuffer buffer = request.CreateBufferedCopy(Int32.MaxValue);
                    request = buffer.CreateMessage();
                    var header = new QueryOptionsHeader(queryParts, includeTotalCount == true);
                    request.Headers.Add(header);
                }
            }

            return(null);
        }
 public object BeforeSendRequest(ref Message request, IClientChannel channel)
 {
     // make sure the channel uses the shared cookie container
     channel.GetProperty <IHttpCookieContainerManager>().CookieContainer =
         this._cookieContainer;
     return(null);
 }
Example #4
0
        public object BeforeSendRequest([CanBeNull] ref Message request, [CanBeNull] IClientChannel channel)
        {
            var cookieManager = channel.GetProperty <IHttpCookieContainerManager>();

            cookieManager.CookieContainer = FilterCookies(cookieManager.CookieContainer);

            return(null);
        }
Example #5
0
        //Called by the client to overwrite context with context bindings
        public static void SetContext(IClientChannel innerChannel, IDictionary <string, string> context)
        {
            Debug.Assert((innerChannel as ICommunicationObject).State != CommunicationState.Opened);

            IContextManager contextManager = innerChannel.GetProperty <IContextManager>();

            contextManager.SetContext(context);
        }
Example #6
0
 public void Initialize(IClientChannel channel)
 {
     Console.WriteLine("Client {0} initialized", channel.SessionId);
     Console.WriteLine("Client {0} initialized", channel.GetProperty <object>().GetHashCode());
     //channel.GetProperty<BooksServiceImpl>();
     channel.Closed  += ClientDisconnected;
     channel.Faulted += ClientDisconnected;
 }
Example #7
0
        //Creates new context containing the new value and the old ones from the proxy
        public static IDictionary <string, string> UpdateContext(IClientChannel innerChannel, string key, string value)
        {
            IContextManager contextManager = innerChannel.GetProperty <IContextManager>();

            IDictionary <string, string> context = new Dictionary <string, string>(contextManager.GetContext());

            context[key] = value;
            return(context);
        }
Example #8
0
        static public IDictionary <string, string> ExtractContextFromChannel(IClientChannel channel)
        {   // extract context from channel
            IContextManager cm = channel.GetProperty <IContextManager>();

            if ((cm != null) && (cm.Enabled))
            {   // attempt to extract context from channel
                return(cm.GetContext());
            }
            return(null);
        }
Example #9
0
        public static TChannel CreateChannelWithJwtToken <TChannel>(this ChannelFactory <TChannel> channelFactory,
                                                                    JwtSecurityToken jwtSecurityToken)
        {
            var channel = channelFactory.CreateChannel();

            IClientChannel clientChannel = (IClientChannel)channel;

            clientChannel.GetProperty <ChannelParameterCollection>().Add(jwtSecurityToken);

            return(channel);
        }
Example #10
0
 public static Guid GetInstanceId(IClientChannel innerChannel)
 {
     try
     {
         string instanceId = innerChannel.GetProperty <IContextManager>().GetContext()[InstanceIdKey];
         return(new Guid(instanceId));
     }
     catch (KeyNotFoundException)
     {
         return(Guid.Empty);
     }
 }
Example #11
0
 // Apply Context to an IClientChannel
 static public bool ApplyContextToChannel(IDictionary<string, string> context, IClientChannel channel)
 {
     if (context != null)
     {
         IContextManager cm = channel.GetProperty<IContextManager>();
         if ((cm != null) && (cm.Enabled))
         {   // apply context to ContextChannel
             cm.SetContext(context);
             return true;
         }
     }
     return false;
 }
Example #12
0
 // Apply Context to an IClientChannel
 static public bool ApplyContextToChannel(IDictionary <string, string> context, IClientChannel channel)
 {
     if (context != null)
     {
         IContextManager cm = channel.GetProperty <IContextManager>();
         if ((cm != null) && (cm.Enabled))
         {   // apply context to ContextChannel
             cm.SetContext(context);
             return(true);
         }
     }
     return(false);
 }
        public object BeforeSendRequest(ref Message request, IClientChannel channel)
        {
            var jwtSecurityToken =
                channel.GetProperty <ChannelParameterCollection>().OfType <JwtSecurityToken>().FirstOrDefault();

            if (jwtSecurityToken == null)
            {
                throw new ArgumentException(
                          "JwtSecurityToken not set in the ChannelParameterCollection, please make sure to use the CreateChannelWithJwtToken extension method");
            }

            var property = new HttpRequestMessageProperty();

            var jwtEncodedString = jwtSecurityToken.RawData;

            property.Headers.Add(HttpRequestHeader.Authorization, jwtEncodedString);
            request.Properties.Add(HttpRequestMessageProperty.Name, property);
            return(null);
        }
        void CallEnd(IAsyncResult result, out Exception exception)
        {
            try
            {
                SecurityToken token = credentials.GetInfoCardTokenCallback.EndInvoke(result);

                ChannelParameterCollection channelParameters =
                    proxy.GetProperty <ChannelParameterCollection>();

                if (null != channelParameters)
                {
                    channelParameters.Add(new InfoCardChannelParameter(token, relyingPartyIssuer, requiresInfoCard));
                }
                exception = null;
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }
                exception = e;
            }
        }
 public object BeforeSendRequest(ref Message request, IClientChannel channel)
 {
     // make sure the channel uses the shared cookie container
     channel.GetProperty<IHttpCookieContainerManager>().CookieContainer =
         this._cookieContainer;
     return null;
 }
Example #16
0
 public static void SetContextId(IClientChannel innerChannel, string contextId)
 {
     IContextManager cntxManager = innerChannel.GetProperty<IContextManager>();
       IDictionary<string, string> context = cntxManager.GetContext();
       context.Add(CONTEXT_KEY, contextId);
       cntxManager.SetContext(context);
 }
Example #17
0
 static public IDictionary<string, string> ExtractContextFromChannel(IClientChannel channel)
 {   // extract context from channel
     IContextManager cm = channel.GetProperty<IContextManager>();
     if ((cm != null) && (cm.Enabled))
     {   // attempt to extract context from channel
         return cm.GetContext();
     }
     return null;
 }