public void ChannelDispatchers_WithDebug() { ServiceHost h = new ServiceHost(typeof(AllActions), new Uri("http://localhost:8080")); h.AddServiceEndpoint(typeof(AllActions).FullName, new BasicHttpBinding(), "address"); ServiceMetadataBehavior b = new ServiceMetadataBehavior(); b.HttpGetEnabled = true; b.HttpGetUrl = new Uri("http://localhost:8080"); h.Description.Behaviors.Add(b); h.Open(); Assert.AreEqual(h.ChannelDispatchers.Count, 2, "#1"); ChannelDispatcher channelDispatcher = h.ChannelDispatchers[1] as ChannelDispatcher; Assert.IsNotNull(channelDispatcher, "#2"); Assert.IsTrue(channelDispatcher.Endpoints.Count == 1, "#3"); EndpointAddressMessageFilter filter = channelDispatcher.Endpoints [0].AddressFilter as EndpointAddressMessageFilter; Assert.IsNotNull(filter, "#4"); Assert.IsTrue(filter.Address.Equals(new EndpointAddress("http://localhost:8080")), "#5"); Assert.IsFalse(filter.IncludeHostNameInComparison, "#6"); Assert.IsTrue(channelDispatcher.Endpoints [0].ContractFilter is MatchAllMessageFilter, "#7"); h.Close(); }
public void ChannelDispatchers_NoDebug() { ServiceHost h = new ServiceHost(typeof(AllActions), new Uri("http://localhost:8080")); h.AddServiceEndpoint(typeof(AllActions).FullName, new BasicHttpBinding(), "address"); ServiceDebugBehavior b = h.Description.Behaviors.Find <ServiceDebugBehavior> (); b.HttpHelpPageEnabled = false; h.Open(); try { Assert.AreEqual(h.ChannelDispatchers.Count, 1); ChannelDispatcher channelDispatcher = h.ChannelDispatchers[0] as ChannelDispatcher; Assert.IsNotNull(channelDispatcher, "#1"); Assert.IsTrue(channelDispatcher.Endpoints.Count == 1, "#2"); EndpointAddressMessageFilter filter = channelDispatcher.Endpoints [0].AddressFilter as EndpointAddressMessageFilter; Assert.IsNotNull(filter, "#3"); Assert.IsTrue(filter.Address.Equals(new EndpointAddress("http://localhost:8080/address")), "#4"); Assert.IsFalse(filter.IncludeHostNameInComparison, "#5"); Assert.IsTrue(channelDispatcher.Endpoints [0].ContractFilter is MatchAllMessageFilter, "#6"); } finally { h.Close(); } }
public ReplySessionChannelListener(Binding.SolipsistTransportBindingElement element, BindingContext context) : base(context.Binding) { _element = element; _context = context; _localAddress = new EndpointAddress(new Uri(context.ListenUriBaseAddress, context.ListenUriRelativeAddress)); _filter = new EndpointAddressMessageFilter(_localAddress); }
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); }
private void SetEndpointAddressFilterToIgnorePort(ServiceHostBase service) { for (int i = 0; i < service.ChannelDispatchers.Count; i++) { ChannelDispatcher dispatcher = service.ChannelDispatchers[i] as ChannelDispatcher; if ((dispatcher != null) && IsSchemeHttpOrHttps(dispatcher.Listener.Uri.Scheme)) { for (int j = 0; j < dispatcher.Endpoints.Count; j++) { EndpointDispatcher dispatcher2 = dispatcher.Endpoints[j]; EndpointAddressMessageFilter addressFilter = dispatcher2.AddressFilter as EndpointAddressMessageFilter; if (addressFilter != null) { addressFilter.ComparePort = false; } } } } }
void SetEndpointAddressFilterToIgnorePort(ServiceHostBase service) { for (int i = 0; i < service.ChannelDispatchers.Count; i++) { ChannelDispatcher channelDispatcher = service.ChannelDispatchers[i] as ChannelDispatcher; if (channelDispatcher != null) { if (IsSchemeHttpOrHttps(channelDispatcher.Listener.Uri.Scheme)) { for (int j = 0; j < channelDispatcher.Endpoints.Count; j++) { EndpointDispatcher endpointDispatcher = channelDispatcher.Endpoints[j]; EndpointAddressMessageFilter endpointAddressMessageFilter = endpointDispatcher.AddressFilter as EndpointAddressMessageFilter; if (endpointAddressMessageFilter != null) { endpointAddressMessageFilter.ComparePort = false; } } } } } }
public void Match () { EndpointAddressMessageFilter f = new EndpointAddressMessageFilter (new EndpointAddress ("http://localhost:8080")); Assert.IsTrue (f.Match (CreateMessageWithTo ("http://localhost:8080")), "#1"); Assert.IsTrue (f.Match (CreateMessageWithTo (new Uri ("http://localhost:8080"))), "#1-2"); Assert.IsFalse (f.Match (CreateMessageWithTo (anonymous_uri)), "#2"); Assert.IsFalse (f.Match (CreateMessageWithTo (EndpointAddress.AnonymousUri)), "#3"); Assert.IsFalse (f.Match (CreateMessageWithTo (EndpointAddress.NoneUri)), "#4"); // no To header Assert.IsFalse (f.Match (Message.CreateMessage (MessageVersion.Default, "urn:myaction")), "#5"); Assert.IsTrue (f.Match (CreateMessageWithTo ("http://10.1.1.1:8080")), "#6"); Assert.IsFalse (f.Match (CreateMessageWithTo ("http://10.1.1.1:8081")), "#7"); f = new EndpointAddressMessageFilter (new EndpointAddress ("http://localhost:8080/abc"), true); Assert.IsFalse (f.Match (CreateMessageWithTo ("http://127.0.0.2:8080/abc")), "#8"); Assert.IsTrue (f.Match (CreateMessageWithTo ("http://localhost:8080/abc?wsdl")), "#9"); f = new EndpointAddressMessageFilter (new EndpointAddress ("http://localhost:8080/abc?foo"), true); Assert.IsTrue (f.Match (CreateMessageWithTo ("http://localhost:8080/abc?wsdl")), "#10"); }
public void Match() { EndpointAddressMessageFilter f = new EndpointAddressMessageFilter(new EndpointAddress("http://localhost:8080")); Assert.IsTrue(f.Match(CreateMessageWithTo("http://localhost:8080")), "#1"); Assert.IsTrue(f.Match(CreateMessageWithTo(new Uri("http://localhost:8080"))), "#1-2"); Assert.IsFalse(f.Match(CreateMessageWithTo(anonymous_uri)), "#2"); Assert.IsFalse(f.Match(CreateMessageWithTo(EndpointAddress.AnonymousUri)), "#3"); Assert.IsFalse(f.Match(CreateMessageWithTo(EndpointAddress.NoneUri)), "#4"); // no To header Assert.IsFalse(f.Match(Message.CreateMessage(MessageVersion.Default, "urn:myaction")), "#5"); Assert.IsTrue(f.Match(CreateMessageWithTo("http://10.1.1.1:8080")), "#6"); Assert.IsFalse(f.Match(CreateMessageWithTo("http://10.1.1.1:8081")), "#7"); f = new EndpointAddressMessageFilter(new EndpointAddress("http://localhost:8080/abc"), true); Assert.IsFalse(f.Match(CreateMessageWithTo("http://127.0.0.2:8080/abc")), "#8"); Assert.IsTrue(f.Match(CreateMessageWithTo("http://localhost:8080/abc?wsdl")), "#9"); f = new EndpointAddressMessageFilter(new EndpointAddress("http://localhost:8080/abc?foo"), true); Assert.IsTrue(f.Match(CreateMessageWithTo("http://localhost:8080/abc?wsdl")), "#10"); }
/// <summary> /// Adds the service bus entry. /// </summary> /// <param name="message">The message.</param> private void AddServiceBusEntry(RouteMeModel message) { //Load the contract assembly from blob storage //Get the current type of contract to add to the client endpoint var storageConnection = CloudConfigurationManager.GetSetting("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString"); var cloudStorage = new ReliableCloudBlobStorage(StorageAccountInfo.Parse(storageConnection)); var contractAssemblyContainer = CloudConfigurationManager.GetSetting("AssemblyContainerName"); var contractAssemblyName = CloudConfigurationManager.GetSetting("ContractAssemblyName"); byte[] data = null; using (MemoryStream mstream = new MemoryStream()) { var gotIt = cloudStorage.Get(contractAssemblyContainer, contractAssemblyName, mstream); if (gotIt) { //Get the byte content. This methods does not care about the position data = mstream.ToArray(); } } //Now we load the contract assembly var assembly = Assembly.Load(data); Type contractType = assembly.GetType(message.ContractName); //The contract description we use var conDesc = ContractDescription.GetContract(contractType); var HTTPbinding = new BasicHttpBinding(); var currentServiceEndPoint = new ServiceEndpoint( conDesc, HTTPbinding, new EndpointAddress(message.EndPointAddress)); currentServiceEndPoint.Name = message.ServiceName; var routerMainEndpoint = owner.Description.Endpoints.Where(ep => ep.Name == "RouterMain").FirstOrDefault(); var conDescRouter = ContractDescription.GetContract(typeof(IRequestReplyRouter)); var rEndPoint = new ServiceEndpoint(conDescRouter, new BasicHttpBinding(), new EndpointAddress(routerMainEndpoint.Address.Uri.OriginalString + "/" + message.ServiceName)); rEndPoint.Name = message.ServiceName; this.owner.AddServiceEndpoint(rEndPoint); var addressFilter = new EndpointAddressMessageFilter(new EndpointAddress(routerMainEndpoint.Address.Uri.OriginalString + "/" + message.ServiceName)); //We don't want to route on headers only rc.RouteOnHeadersOnly = false; //Add the filter table rc.FilterTable.Add(addressFilter, new List <ServiceEndpoint>() { currentServiceEndPoint }); //Apply the dynamic configuration this.owner.Extensions.Find <RoutingExtension>().ApplyConfiguration(rc); }
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; }