コード例 #1
1
        // In this tutorial, the routing service is hosted using a console application to avoid over-complicating the routing
        // proof of concept with complex IIS, hosting, and web.config configurations.  The console hosts can be easily tested
        // without any configuration necessary
        static void Main(string[] args)
        {
            // I am sure that you realize that all of the following could be done in the web.config, but I opted to do it
            // programmitically so that each individual component can be explained along the way
            using (var host = new ServiceHost(typeof(RoutingService)))
            {
                // In this step, we create an BasicHttp binding endpoint that will be used by the hosting interface to
                // expose our routing service.
                // Note the use of the IRequestReplyRouter contract
                ContractDescription contract = ContractDescription.GetContract(typeof(IRequestReplyRouter));
                Binding binding = new BasicHttpBinding();
                var endpointAddress = new EndpointAddress("http://*****:*****@"http://services.bloggedbychris.com/practice/routing/v1/Version/GetVersion");
                var v1Endpoint = new [] {new ServiceEndpoint(contract, new BasicHttpBinding(), new EndpointAddress("http://*****:*****@"http://services.bloggedbychris.com/practice/routing/v2/Version/GetVersion");
                var v2Endpoint = new[] {new ServiceEndpoint(contract, new BasicHttpBinding(), new EndpointAddress("http://localhost:9092/routing/version/"))};
                routingConfiguration.FilterTable.Add(v2Filter, v2Endpoint);

                // Here we add our routing configuration as a service behavior for our routing service
                var routingBehavior = new RoutingBehavior(routingConfiguration);
                host.Description.Behaviors.Add(routingBehavior);

                // Open the ServiceHost to create listeners
                // and start listening for messages.
                host.Open();

                // The service can now be accessed.
                Console.WriteLine("The service is ready.");
                Console.WriteLine("Press <ENTER> to terminate service.");
                Console.WriteLine();
                Console.ReadLine();
            }
        }
コード例 #2
0
ファイル: actionfilter.cs プロジェクト: ruo2012/samples-1
        public static void Main()
        {
            // Create several action filters.
            // <Snippet2>
            ActionMessageFilter myActFltr = new ActionMessageFilter("1st Action", "2nd Action");
            // </Snippet2>
            ActionMessageFilter yourActFltr = new ActionMessageFilter("Your Action");

            // Display the ActionMessageFilter actions.
            ReadOnlyCollection <string> results = myActFltr.Actions;

            foreach (string result in results)
            {
                System.Console.WriteLine(result);
            }

            // Create a message.
            Message message = Message.CreateMessage(MessageVersion.Soap12WSAddressing10, "myBody");

            // Test the message action against a single action filter.
            bool test1 = myActFltr.Match(message);
            bool test2 = yourActFltr.Match(message);

            System.Console.WriteLine("The result of test1 is {0}", test1);
            System.Console.WriteLine("The result of test2 is {0}", test2);
        }
コード例 #3
0
        public override bool Match(System.ServiceModel.Channels.Message message)
        {
            //wHaibo 2013-05-14 Action再调整
            ActionMessageFilter actionFilter = filter as ActionMessageFilter;

            if (actionFilter != null)
            {
                if (!actionFilter.Actions.Contains(message.Headers.Action) && message.Headers.Action != null)
                {
                    string oldAction  = message.Headers.Action;
                    string actionName = actionFilter.Actions.FirstOrDefault(x => x.EndsWith(message.Headers.Action));
                    if (String.IsNullOrEmpty(actionName))
                    {
                        actionName = actionFilter.Actions.FirstOrDefault(x => x.EndsWith(message.Headers.Action + "Request"));
                    }
                    if (!String.IsNullOrEmpty(actionName))
                    {
                        message.Headers.Action = actionName;
                        receiveLogger.Trace("调整Action:{0}---->{1}", oldAction, message.Headers.Action);
                    }
                }
            }

            bool isMatch = filter.Match(message);

            if (!isMatch)
            {
                receiveLogger.Error("收到消息,但是Action不匹配:\r\n地址:{0} \r\n消息:\r\n{1}\r\n", address.Uri.ToString(), message.ToString());
            }
            return(isMatch);
        }
 private ActionMessageFilter GetInnerFilter()
 {
     if (this.innerFilter == null)
     {
         this.innerFilter = new ActionMessageFilter(new string[] { this.Action });
     }
     return this.innerFilter;
 }
コード例 #5
0
 private ActionMessageFilter GetInnerFilter()
 {
     if (this.innerFilter == null)
     {
         this.innerFilter = new ActionMessageFilter(new string[] { this.Action });
     }
     return(this.innerFilter);
 }
コード例 #6
0
        static CorrelationQuery CreateDefaultCorrelationQuery(CorrelationQuery query, string action, CorrelationDataDescription data, ref bool shouldPreserveMessage)
        {
            MessageQuery messageQuery = new XPathMessageQuery
            {
                Expression = string.Format(CultureInfo.InvariantCulture, defaultQueryFormat, data.Name),
                Namespaces = new XPathMessageContext()
            };

            if (data.IsOptional)
            {
                messageQuery = new OptionalMessageQuery
                {
                    Query = messageQuery
                };
            }


            if (query == null)
            {
                MessageFilter filter;
                // verify if the data name is added by the context channel
                bool isContextQuery = (data.Name == contextCorrelationName);

                // if there is a query that is not a context query set it to true since we might read from
                // the message body
                if (!shouldPreserveMessage && !isContextQuery)
                {
                    shouldPreserveMessage = true;
                }
                // this is a server side query, we use an action filter
                if (action == MessageHeaders.WildcardAction)
                {
                    filter = new MatchAllMessageFilter();
                }
                else
                {
                    filter = new ActionMessageFilter(action);
                }

                return(new CorrelationQuery
                {
                    Where = filter,

                    IsDefaultContextQuery = isContextQuery,

                    Select = new MessageQuerySet
                    {
                        { data.Name, messageQuery }
                    }
                });
            }
            else
            {
                query.Select[data.Name] = messageQuery;
                return(query);
            }
        }
コード例 #7
0
        ActionMessageFilter GetInnerFilter()
        {
            if (this.innerFilter == null)
            {
                this.innerFilter = new ActionMessageFilter(this.Action);
            }

            return this.innerFilter;
        }
        ActionMessageFilter GetInnerFilter()
        {
            if (this.innerFilter == null)
            {
                this.innerFilter = new ActionMessageFilter(this.Action);
            }

            return(this.innerFilter);
        }
コード例 #9
0
        public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
        {
            endpointDispatcher.DispatchRuntime.OperationSelector = this;

            ActionMessageFilter mf = endpointDispatcher.ContractFilter as ActionMessageFilter;

            List <string> strList = new List <string>(mf.Actions);

            strList.Add(string.Empty);

            endpointDispatcher.ContractFilter = new ActionMessageFilter(strList.ToArray());
        }
コード例 #10
0
ファイル: ActionFilterTest.cs プロジェクト: nickchal/pash
		public void Match ()
		{
			ActionMessageFilter f = new ActionMessageFilter ("foo");
			Assert.AreEqual (1, f.Actions.Count, "#1");
			Message msg = Message.CreateMessage (MessageVersion.Default, "foo");
			Assert.AreEqual ("foo", msg.Headers.Action, "#2");
			Assert.IsTrue (f.Match (msg), "#3");
			msg = Message.CreateMessage (MessageVersion.Default, "bar");
			Assert.IsFalse (f.Match (msg), "#4");

			f = new ActionMessageFilter ("foo", "bar");
			Assert.AreEqual (2, f.Actions.Count, "#5");
			Assert.IsTrue (f.Match (msg), "#6");
		}
コード例 #11
0
 static void Main(string[] args)
 {
     using (ServiceHost host = new ServiceHost(typeof(CalculatorService)))
     {
         host.Open();
         ChannelDispatcher   channelDispatcher  = (ChannelDispatcher)host.ChannelDispatchers[0];
         EndpointDispatcher  endpointDispatcher = channelDispatcher.Endpoints[0];
         ActionMessageFilter messageFilter      = (ActionMessageFilter)endpointDispatcher.ContractFilter;
         foreach (string action in messageFilter.Actions)
         {
             Console.WriteLine(action);
         }
         Console.Read();
     }
 }
コード例 #12
0
ファイル: Form1.cs プロジェクト: EDDiscovery/KeyLogger
        public KeyLogger()
        {
            InitializeComponent();
            actionfilesmessagefilter = new ActionMessageFilter(this);
            Application.AddMessageFilter(actionfilesmessagefilter);
            ws = new Stopwatch();
            ws.Start();
            richTextBox1.Text = Environment.CommandLine + Environment.NewLine;

#if false
            // some test code exercising the key win32 funcs

            for (int i = 0; i <= 255; i++)
            {
                Keys ret = (Keys)BaseUtils.Win32.UnsafeNativeMethods.VkKeyScan((char)i);
                System.Diagnostics.Debug.WriteLine(i + " " + (int)ret + " " + ret.ToString());
            }

            for (int i = 0; i <= 255; i++)
            {
                uint v = BaseUtils.Win32.UnsafeNativeMethods.MapVirtualKey((uint)i, 2);
                if (v > 0)
                {
                    string vk = (v > 0) ? ((Keys)i).ToString() : "";
                    char   c  = (v > 0) ? ((char)v) : '?';
                    System.Diagnostics.Debug.WriteLine(i + " " + vk + " = " + v + " = " + c);
                }
            }

            for (int i = 1; i < 0x5f; i++)
            {
                StringBuilder s = new StringBuilder();
                BaseUtils.Win32.UnsafeNativeMethods.GetKeyNameText(i << 16, s, 100);
                StringBuilder es = new StringBuilder();
                BaseUtils.Win32.UnsafeNativeMethods.GetKeyNameText(i << 16 | 1 << 24, es, 100);
                System.Diagnostics.Debug.WriteLine("SC {0:x} {1,20} {2,20}", i, s.ToNullSafeString(), es.ToNullSafeString());
            }

            {
                char  c  = '²';
                short vk = BaseUtils.Win32.UnsafeNativeMethods.VkKeyScan(c);
                if (vk != -1)
                {
                    System.Diagnostics.Debug.WriteLine("{0} = {1:x} {2}", c, vk, ((Keys)vk).VKeyToString());
                }
            }
#endif
        }
コード例 #13
0
        public void SpecificActionTest()
        {
            //EndpointDispatcher d = new EndpointDispatcher(
            ServiceHost h = new ServiceHost(typeof(SpecificAction), new Uri("http://localhost:8080"));

            h.AddServiceEndpoint(typeof(Action1Interface), new BasicHttpBinding(), "address");

            h.Open();
            ChannelDispatcher   d            = h.ChannelDispatchers [0] as ChannelDispatcher;
            EndpointDispatcher  ed           = d.Endpoints [0] as EndpointDispatcher;
            ActionMessageFilter actionFilter = ed.ContractFilter as ActionMessageFilter;

            Assert.IsNotNull(actionFilter, "#1");
            Assert.IsTrue(actionFilter.Actions.Count == 1, "#2");
            h.Close();
        }
コード例 #14
0
        public void Match()
        {
            ActionMessageFilter f = new ActionMessageFilter("foo");

            Assert.AreEqual(1, f.Actions.Count, "#1");
            Message msg = Message.CreateMessage(MessageVersion.Default, "foo");

            Assert.AreEqual("foo", msg.Headers.Action, "#2");
            Assert.IsTrue(f.Match(msg), "#3");
            msg = Message.CreateMessage(MessageVersion.Default, "bar");
            Assert.IsFalse(f.Match(msg), "#4");

            f = new ActionMessageFilter("foo", "bar");
            Assert.AreEqual(2, f.Actions.Count, "#5");
            Assert.IsTrue(f.Match(msg), "#6");
        }
コード例 #15
0
        internal MessageFilter CreateFilter(XmlNamespaceManager xmlNamespaces, FilterElementCollection filters)
        {
            MessageFilter filter;

            switch (this.FilterType)
            {
            case FilterType.Action:
                filter = new ActionMessageFilter(this.FilterData);
                break;

            case FilterType.EndpointAddress:
                filter = new EndpointAddressMessageFilter(new EndpointAddress(this.FilterData), false);
                break;

            case FilterType.PrefixEndpointAddress:
                filter = new PrefixEndpointAddressMessageFilter(new EndpointAddress(this.FilterData), false);
                break;

            case FilterType.And:
                MessageFilter filter1 = filters[this.Filter1].CreateFilter(xmlNamespaces, filters);
                MessageFilter filter2 = filters[this.Filter2].CreateFilter(xmlNamespaces, filters);
                filter = new StrictAndMessageFilter(filter1, filter2);
                break;

            case FilterType.EndpointName:
                filter = new EndpointNameMessageFilter(this.FilterData);
                break;

            case FilterType.MatchAll:
                filter = new MatchAllMessageFilter();
                break;

            case FilterType.Custom:
                filter = CreateCustomFilter(this.CustomType, this.FilterData);
                break;

            case FilterType.XPath:
                filter = new XPathMessageFilter(this.FilterData, xmlNamespaces);
                break;

            default:
                // We can't really ever get here because set_FilterType performs validation.
                throw FxTrace.Exception.AsError(new InvalidOperationException());
            }
            return(filter);
        }
コード例 #16
0
        public void ActionConfigureKeys()
        {
            actionfileskeyeventskeydown = GetKeyEvent(ActionEventEDList.onKeyPress.TriggerName, "KeyPress");
            actionfileskeyeventskeyup   = GetKeyEvent(ActionEventEDList.onKeyReleased.TriggerName, "KeyPress");

            if (actionfileskeyeventskeydown.HasChars() || actionfileskeyeventskeyup.HasChars())
            {
                if (actionfilesmessagefilter == null)
                {
                    actionfilesmessagefilter = new ActionMessageFilter(discoveryform, this, keyignoredforms);
                    Application.AddMessageFilter(actionfilesmessagefilter);
                }
            }
            else if (actionfilesmessagefilter != null)
            {
                Application.RemoveMessageFilter(actionfilesmessagefilter);
                actionfilesmessagefilter = null;
            }
        }
コード例 #17
0
        private static CorrelationQuery CreateDefaultCorrelationQuery(CorrelationQuery query, string action, CorrelationDataDescription data, ref bool shouldPreserveMessage)
        {
            XPathMessageQuery query5 = new XPathMessageQuery {
                Expression = string.Format(CultureInfo.InvariantCulture, "sm:correlation-data('{0}')", new object[] { data.Name }),
                Namespaces = new XPathMessageContext()
            };
            MessageQuery query2 = query5;

            if (data.IsOptional)
            {
                OptionalMessageQuery query3 = new OptionalMessageQuery {
                    Query = query2
                };
                query2 = query3;
            }
            if (query == null)
            {
                MessageFilter filter;
                bool          flag = data.Name == "wsc-instanceId";
                if (!shouldPreserveMessage && !flag)
                {
                    shouldPreserveMessage = true;
                }
                if (action == "*")
                {
                    filter = new MatchAllMessageFilter();
                }
                else
                {
                    filter = new ActionMessageFilter(new string[] { action });
                }
                CorrelationQuery query4 = new CorrelationQuery {
                    Where = filter,
                    IsDefaultContextQuery = flag
                };
                MessageQuerySet set = new MessageQuerySet();
                set.Add(data.Name, query2);
                query4.Select = set;
                return(query4);
            }
            query.Select[data.Name] = query2;
            return(query);
        }
コード例 #18
0
        void ActionConfigureKeys()
        {
            List <Tuple <string, ConditionEntry.MatchType> > ret = actionfiles.ReturnValuesOfSpecificConditions("KeyPress", new List <ConditionEntry.MatchType>()
            {
                ConditionEntry.MatchType.Equals, ConditionEntry.MatchType.IsOneOf
            });                                                                                                                                                                                                                              // need these to decide

            if (ret.Count > 0)
            {
                actionfileskeyevents = "";
                foreach (Tuple <string, ConditionEntry.MatchType> t in ret)                  // go thru the list, making up a comparision string with Name, on it..
                {
                    if (t.Item2 == ConditionEntry.MatchType.Equals)
                    {
                        actionfileskeyevents += "<" + t.Item1 + ">";
                    }
                    else
                    {
                        StringParser  p     = new StringParser(t.Item1);
                        List <string> klist = p.NextQuotedWordList();
                        if (klist != null)
                        {
                            foreach (string s in klist)
                            {
                                actionfileskeyevents += "<" + s + ">";
                            }
                        }
                    }
                }

                if (actionfilesmessagefilter == null)
                {
                    actionfilesmessagefilter = new ActionMessageFilter(discoveryform, this);
                    Application.AddMessageFilter(actionfilesmessagefilter);
                }
            }
            else if (actionfilesmessagefilter != null)
            {
                Application.RemoveMessageFilter(actionfilesmessagefilter);
                actionfilesmessagefilter = null;
            }
        }
コード例 #19
0
        internal MessageFilter CreateFilter(XmlNamespaceManager xmlNamespaces, FilterElementCollection filters)
        {
            MessageFilter filter;

            switch (this.FilterType)
            {
                case FilterType.Action:
                    filter = new ActionMessageFilter(this.FilterData);
                    break;
                case FilterType.EndpointAddress:
                    filter = new EndpointAddressMessageFilter(new EndpointAddress(this.FilterData), false);
                    break;
                case FilterType.PrefixEndpointAddress:
                    filter = new PrefixEndpointAddressMessageFilter(new EndpointAddress(this.FilterData), false);
                    break;
                case FilterType.And:
                    MessageFilter filter1 = filters[this.Filter1].CreateFilter(xmlNamespaces, filters);
                    MessageFilter filter2 = filters[this.Filter2].CreateFilter(xmlNamespaces, filters);
                    filter = new StrictAndMessageFilter(filter1, filter2);
                    break;
                case FilterType.EndpointName:
                    filter = new EndpointNameMessageFilter(this.FilterData);
                    break;
                case FilterType.MatchAll:
                    filter = new MatchAllMessageFilter();
                    break;
                case FilterType.Custom:
                    filter = CreateCustomFilter(this.CustomType, this.FilterData);
                    break;
                case FilterType.XPath:
                    filter = new XPathMessageFilter(this.FilterData, xmlNamespaces);
                    break;
                default:
                    // We can't really ever get here because set_FilterType performs validation.
                    throw FxTrace.Exception.AsError(new InvalidOperationException());
            }
            return filter;
        }