Пример #1
0
		void UseCase1Core (Uri serviceUri, AnnouncementEndpoint aEndpoint, DiscoveryEndpoint dEndpoint)
		{
			// actual service, announcing to 4989
			var host = new ServiceHost (typeof (TestService));
			var sdb = new ServiceDiscoveryBehavior ();
			sdb.AnnouncementEndpoints.Add (aEndpoint);
			host.Description.Behaviors.Add (sdb);
			host.AddServiceEndpoint (typeof (ITestService), new BasicHttpBinding (), serviceUri);
			host.Open ();
			// It does not start announcement very soon, so wait for a while.
			Thread.Sleep (1000);
			foreach (var edm in host.Extensions.Find<DiscoveryServiceExtension> ().PublishedEndpoints)
				TextWriter.Null.WriteLine ("Published Endpoint: " + edm.Address);
			try {
				// actual client, with DiscoveryClientBindingElement
				var be = new DiscoveryClientBindingElement () { DiscoveryEndpointProvider = new ManagedDiscoveryEndpointProvider (dEndpoint) };
				var clientBinding = new CustomBinding (new BasicHttpBinding ());
				clientBinding.Elements.Insert (0, be);
				var cf = new ChannelFactory<ITestService> (clientBinding, DiscoveryClientBindingElement.DiscoveryEndpointAddress);
				var ch = cf.CreateChannel ();
				Assert.AreEqual ("TEST", ch.Echo ("TEST"), "#1");
			} finally {
				host.Close ();
			}
		}
Пример #2
0
        public DiscoverableAttribute(Type resolverType, string[] ignoredContractTypeNames, string[] ignoredEndpoints, params Type[] pluginTypes)
        {
            _ignoredContractTypeNames = ignoredContractTypeNames ?? new string[] { };
            _ignoredEndpoints = ignoredEndpoints ?? new string[] { };

            var resolver = Activator.CreateInstance(resolverType) as IDiscoveryServiceResolver;
            var binding = resolver.AnnouncementBinding;
            var endpointUrl = resolver.AnnouncementEndpoint;
            _announcementEndpoint = new AnnouncementEndpoint(binding, new EndpointAddress(endpointUrl));

            var serviceDiscoveryBehavior = new ServiceDiscoveryBehavior();
            serviceDiscoveryBehavior.AnnouncementEndpoints.Add(_announcementEndpoint);
            _serviceDiscoveryBehavior = serviceDiscoveryBehavior;

            // initialize the plugin instances (ensure the parameter is not null)
            var plugins = new List<PluginBase>();
            foreach (var plugInType in pluginTypes ?? new Type[] { })
            {
                var plugin = Activator.CreateInstance(plugInType) as PluginBase;
                if (plugin != null)
                {
                    plugins.Add(plugin);
                }
            }
            _plugins = plugins;
        }
Пример #3
0
	static void RunCodeUnderDiscoveryHost (Uri serviceUri, Uri aHostUri, Action<Uri,AnnouncementEndpoint,DiscoveryEndpoint> action)
	{
		var abinding = new CustomBinding (new HttpTransportBindingElement ());
		var aAddress = new EndpointAddress (aHostUri);
		var aEndpoint = new AnnouncementEndpoint (abinding, aAddress);
		var dBinding = new CustomBinding (new TextMessageEncodingBindingElement (), new TcpTransportBindingElement ());
		var dEndpoint = new DiscoveryEndpoint (DiscoveryVersion.WSDiscovery11, ServiceDiscoveryMode.Adhoc, dBinding, new EndpointAddress ("net.tcp://localhost:9090/"));

		var ib = new InspectionBehavior ();
		ib.RequestReceived += delegate (ref Message msg, IClientChannel
channel, InstanceContext instanceContext) {
			var mb = msg.CreateBufferedCopy (0x10000);
			msg = mb.CreateMessage ();
			Console.Error.WriteLine (mb.CreateMessage ());
			return null;
			};
		ib.ReplySending += delegate (ref Message msg, object o) {
			var mb = msg.CreateBufferedCopy (0x10000);
			msg = mb.CreateMessage ();
			Console.Error.WriteLine (mb.CreateMessage ());
			};
		dEndpoint.Behaviors.Add (ib);
		aEndpoint.Behaviors.Add (ib);

		action (serviceUri, aEndpoint, dEndpoint);
	}
Пример #4
0
		public AnnouncementClient (AnnouncementEndpoint announcementEndpoint)
		{
			if (announcementEndpoint == null)
				throw new ArgumentNullException ("announcementEndpoint");
			MessageSequenceGenerator = new DiscoveryMessageSequenceGenerator ();
			client = Activator.CreateInstance (announcementEndpoint.DiscoveryVersion.AnnouncementClientType, new object [] {announcementEndpoint});
		}
 public DiscoveryChannelDispatcher(AnnouncementEndpoint endpoint, bool handleAnnounceOnline)
 {
     // The argument endpoint is to indicate "destination".
     // It is different from the destination indicated in
     // "EndpointDiscoveryMetadata" argument in announcement messages sent by the "client".
     this.client = new AnnouncementClient(endpoint);
     this.handle_announce_online = handleAnnounceOnline;
 }
Пример #6
0
		public DiscoveryChannelDispatcher (AnnouncementEndpoint endpoint, bool handleAnnounceOnline)
		{
			// The argument endpoint is to indicate "destination".
			// It is different from the destination indicated in 
			// "EndpointDiscoveryMetadata" argument in announcement messages sent by the "client".
			this.client = new AnnouncementClient (endpoint);
			this.handle_announce_online = handleAnnounceOnline;
		}
        public AnnouncementClient(AnnouncementEndpoint announcementEndpoint)
        {
            if (announcementEndpoint == null)
            {
                throw FxTrace.Exception.ArgumentNull("announcementEndpoint");
            }

            Initialize(announcementEndpoint);
        }
		public WcfDiscoveryExtension AnnounceUsing(AnnouncementEndpoint endpoint)
		{
			if (announceEndpoints == null)
			{
				announceEndpoints = new HashSet<AnnouncementEndpoint>();
			}
			announceEndpoints.Add(endpoint);
			return this;
		}
Пример #9
0
 public AnnouncementClient(AnnouncementEndpoint announcementEndpoint)
 {
     if (announcementEndpoint == null)
     {
         throw new ArgumentNullException("announcementEndpoint");
     }
     MessageSequenceGenerator = new DiscoveryMessageSequenceGenerator();
     client = Activator.CreateInstance(announcementEndpoint.DiscoveryVersion.AnnouncementClientType, new object [] { announcementEndpoint });
 }
Пример #10
0
        public AnnouncementClient(AnnouncementEndpoint announcementEndpoint)
        {
            if (announcementEndpoint == null)
            {
                throw FxTrace.Exception.ArgumentNull("announcementEndpoint");
            }

            Initialize(announcementEndpoint);
        }
 public ManagedProxyDiscoveryServiceHost(IEndpointMetadataProvider endpointMetadataProvider, IDiscoveryServiceResolver discoveryServiceResolver, params PluginBase[] plugins)
     : base(new ManagedProxyDiscoveryService(endpointMetadataProvider, plugins))
 {
     var announcementEndpoint = new AnnouncementEndpoint(discoveryServiceResolver.AnnouncementBinding, new EndpointAddress(discoveryServiceResolver.AnnouncementEndpoint));
     var probeEndpoint = new DiscoveryEndpoint(discoveryServiceResolver.ProbeBinding, new EndpointAddress(discoveryServiceResolver.ProbeEndpoint));
     probeEndpoint.IsSystemEndpoint = false;
     AddServiceEndpoint(announcementEndpoint);
     AddServiceEndpoint(probeEndpoint);
 }
Пример #12
0
        static void Main(string[] args)
        {
            Uri baseAddress = new Uri("net.tcp://localhost:9002/CalculatorService/" + Guid.NewGuid().ToString());
            Uri announcementEndpointAddress = new Uri("net.tcp://localhost:9021/Announcement");
            //create service host
            ServiceHost host = new ServiceHost(typeof(CalculatorService),baseAddress);
            ServiceDebugBehavior sdb = host.Description.Behaviors.Find<ServiceDebugBehavior>();
            if (sdb == null)
            {
                host.Description.Behaviors.Add(
                    new ServiceDebugBehavior() { IncludeExceptionDetailInFaults = true });
            }
            else
            {
                if (!sdb.IncludeExceptionDetailInFaults)
                {
                    sdb.IncludeExceptionDetailInFaults = true;
                }
            }
            //try
            //{
                //add a service endpoint
                ServiceEndpoint netTcpEndpoint = host.AddServiceEndpoint(typeof(ICalculatorService),new NetTcpBinding(),string.Empty);
                //create an announcement endpoint, which points to the Announcement endpoint hosted by the proxy service
                AnnouncementEndpoint announcementEndpoint = new AnnouncementEndpoint(new NetTcpBinding(),new EndpointAddress(announcementEndpointAddress));
                //create a servicediscoveryBehavior and add the announcement endpoint
                ServiceDiscoveryBehavior serviceDiscoveryBehavior = new ServiceDiscoveryBehavior();
                serviceDiscoveryBehavior.AnnouncementEndpoints.Add(announcementEndpoint);
                //add the serviceDiscoveryBehavior to the service host to make the service discovnerable
                host.Description.Behaviors.Add(serviceDiscoveryBehavior);
                //start listening for messages
                host.Open();
                Console.WriteLine("Calculator Service started at {0}", baseAddress);
                Console.WriteLine();
                Console.WriteLine("Press <ENTER> to terminate the service.");
                Console.WriteLine();
                Console.ReadLine();

                host.Close();
            //}
            //catch (CommunicationException e)
            //{
            //    Console.WriteLine(e.Message);
            //}
            //catch (TimeoutException e)
            //{
            //    Console.WriteLine(e.Message);
            //}

            //if (host.State != CommunicationState.Closed)
            //{
            //    Console.WriteLine("Aborting the service...");
            //    host.Abort();
            //}
        }
Пример #13
0
	static void RunCodeUnderDiscoveryHost (Uri serviceUri, Uri dHostUri, Uri aHostUri, Action<Uri,AnnouncementEndpoint,DiscoveryEndpoint> action)
	{
		var abinding = new CustomBinding (new HttpTransportBindingElement ());
		var aAddress = new EndpointAddress (aHostUri);
		var aEndpoint = new AnnouncementEndpoint (abinding, aAddress);
		var dbinding = new CustomBinding (new HttpTransportBindingElement ());
		var dAddress = new EndpointAddress (dHostUri);
		var dEndpoint = new DiscoveryEndpoint (dbinding, dAddress);

		action (serviceUri, aEndpoint, dEndpoint);
	}
Пример #14
0
		public void DefaultValues ()
		{
			var de = new AnnouncementEndpoint ();
			Assert.AreEqual (DiscoveryVersion.WSDiscovery11, de.DiscoveryVersion, "#1");
			Assert.AreEqual (TimeSpan.Zero, de.MaxAnnouncementDelay, "#2");
			Assert.IsNotNull (de.Contract, "#11"); // some version-dependent internal type.
			Assert.AreEqual ("http://docs.oasis-open.org/ws-dd/ns/discovery/2009/01", de.Contract.Namespace, "#11-2");
			Assert.AreEqual ("Client", de.Contract.Name, "#11-3");
			Assert.IsNull (de.Binding, "#12");
			Assert.IsNull (de.Address, "#13");
			Assert.IsNull (de.ListenUri, "#14");
		}
		public AnnouncementBoundDiscoveryService (AnnouncementEndpoint aendpoint)
		{
			var ans = new AnnouncementService ();
			ans.OnlineAnnouncementReceived += RegisterEndpoint;
			ans.OfflineAnnouncementReceived += UnregisterEndpoint;
			ahost = new ServiceHost (ans);
			ahost.AddServiceEndpoint (aendpoint);
			ahost.Description.Behaviors.Find<ServiceDebugBehavior> ().IncludeExceptionDetailInFaults = true;
			ahost.Open ();
			foreach (var cd in ahost.ChannelDispatchers)
				TextWriter.Null.WriteLine ("AnnouncementService.ChannelDispatcher " + cd.Listener.Uri);
		}
Пример #16
0
	static void UseCase1Core (Uri serviceUri, AnnouncementEndpoint aEndpoint, DiscoveryEndpoint dEndpoint)
	{
		var host = new ServiceHost (typeof (TestService));
		var sdb = new ServiceDiscoveryBehavior ();
		sdb.AnnouncementEndpoints.Add (aEndpoint);
		host.Description.Behaviors.Add (sdb);
		host.AddServiceEndpoint (typeof (ITestService), new BasicHttpBinding (), serviceUri);
		host.Open ();
		Console.WriteLine ("Type [CR] to quit ...");
		Console.ReadLine ();
		host.Close ();
	}
Пример #17
0
        public AnnouncementClient(string endpointConfigurationName)
        {
            if (endpointConfigurationName == null)
            {
                throw FxTrace.Exception.ArgumentNull("endpointConfigurationName");
            }

            AnnouncementEndpoint announcementEndpoint =
                ConfigurationUtility.LookupEndpointFromClientSection <AnnouncementEndpoint>(
                    endpointConfigurationName);

            Initialize(announcementEndpoint);
        }
Пример #18
0
	static void RunCodeUnderDiscoveryHost (Uri serviceUri, Uri aHostUri)
	{
		// announcement service
		var abinding = new CustomBinding (new HttpTransportBindingElement ());
		var aAddress = new EndpointAddress (aHostUri);
		var aEndpoint = new AnnouncementEndpoint (abinding, aAddress);
		
		// discovery service
		var dBinding = new CustomBinding (new TextMessageEncodingBindingElement (), new TcpTransportBindingElement ());
		var dEndpoint = new DiscoveryEndpoint (DiscoveryVersion.WSDiscovery11, ServiceDiscoveryMode.Adhoc, dBinding, new EndpointAddress ("net.tcp://" + hostname + ":9090/"));
		// Without this, .NET rejects the host as if it had no service.
		dEndpoint.IsSystemEndpoint = false;
		var ib = new InspectionBehavior ();
		ib.ReplySending += delegate (ref Message msg, object o) {
			var mb = msg.CreateBufferedCopy (0x10000);
			msg = mb.CreateMessage ();
			Console.Error.WriteLine (mb.CreateMessage ());
			};
		ib.RequestReceived += delegate (ref Message msg, IClientChannel channel, InstanceContext instanceContext) {
			var mb = msg.CreateBufferedCopy (0x10000);
			msg = mb.CreateMessage ();
			Console.Error.WriteLine (mb.CreateMessage ());
			return null;
			};
		ib.ReplyReceived += delegate (ref Message msg, object o) {
			var mb = msg.CreateBufferedCopy (0x10000);
			msg = mb.CreateMessage ();
			Console.Error.WriteLine (mb.CreateMessage ());
			};
		ib.RequestSending += delegate (ref Message msg, IClientChannel channel) {
			var mb = msg.CreateBufferedCopy (0x10000);
			msg = mb.CreateMessage ();
			Console.Error.WriteLine (mb.CreateMessage ());
			return null;
			};

		dEndpoint.Behaviors.Add (ib);
		aEndpoint.Behaviors.Add (ib);

		// it internally hosts an AnnouncementService
		using (var inst = new AnnouncementBoundDiscoveryService (aEndpoint)) {
			var host = new ServiceHost (inst);
			host.AddServiceEndpoint (dEndpoint);
			host.Description.Behaviors.Find<ServiceDebugBehavior> ()
				.IncludeExceptionDetailInFaults = true;
			host.Open ();
			Console.WriteLine ("Type [CR] to quit...");
			Console.ReadLine ();
			host.Close ();
		}
	}
Пример #19
0
        static void Main()
        {
            var dnsName = Dns.GetHostName();
            // Define the base address of the service
            var baseAddress = new Uri(string.Format("net.tcp://{0}:9002/CalculatorService/{1}", dnsName, Guid.NewGuid().ToString()));
            // Define the endpoint address where announcement messages will be sent
            var announcementEndpointAddress = new Uri(string.Format("http://{0}:8001/Announcement", dnsName));

            // Create the service host
            var serviceHost = new ServiceHost(typeof(CalculatorService), baseAddress);
            try
            {
                // Add a service endpoint
                var netTcpEndpoint = serviceHost.AddServiceEndpoint(typeof(ICalculatorService), new NetTcpBinding(), string.Empty);

                // Create an announcement endpoint, which points to the Announcement Endpoint hosted by the proxy service.
                var announcementEndpoint = new AnnouncementEndpoint(new WSHttpBinding(SecurityMode.None), new EndpointAddress(announcementEndpointAddress));

                // Create a ServiceDiscoveryBehavior and add the announcement endpoint
                var serviceDiscoveryBehavior = new ServiceDiscoveryBehavior();
                serviceDiscoveryBehavior.AnnouncementEndpoints.Add(announcementEndpoint);

                // Add the ServiceDiscoveryBehavior to the service host to make the service discoverable
                serviceHost.Description.Behaviors.Add(serviceDiscoveryBehavior);

                // Start listening for messages
                serviceHost.Open();

                Console.WriteLine("Calculator Service started at {0}", baseAddress);
                Console.WriteLine();
                Console.WriteLine("Press <ENTER> to terminate the service.");
                Console.WriteLine();
                Console.ReadLine();

                serviceHost.Close();
            }
            catch (CommunicationException e)
            {
                Console.WriteLine(e.Message);
            }
            catch (TimeoutException e)
            {
                Console.WriteLine(e.Message);
            }

            if (serviceHost.State != CommunicationState.Closed)
            {
                Console.WriteLine("Aborting the service...");
                serviceHost.Abort();
            }
        }
Пример #20
0
        private void HeartBeat(IEnumerable<EndpointDiscoveryMetadata> metadatas, AnnouncementEndpoint announcementEndpoint)
        {
            while (true)
            {
                Thread.Sleep(_interval);

                using (var announcementClient = new AnnouncementClient(announcementEndpoint))
                {
                    foreach (var metadata in metadatas)
                    {
                        announcementClient.AnnounceOnline(metadata);
                    }
                }
            }
        }
Пример #21
0
        void Initialize(AnnouncementEndpoint announcementEndpoint)
        {
            if (announcementEndpoint.Binding != null && announcementEndpoint.Binding.MessageVersion.Addressing == AddressingVersion.None)
            {
                throw FxTrace.Exception.Argument(
                          "announcementEndpoint",
                          SR.EndpointWithInvalidMessageVersion(
                              announcementEndpoint.GetType().Name,
                              AddressingVersion.None,
                              this.GetType().Name,
                              AddressingVersion.WSAddressing10,
                              AddressingVersion.WSAddressingAugust2004));
            }

            this.innerClient = announcementEndpoint.DiscoveryVersion.Implementation.CreateAnnouncementInnerClient(announcementEndpoint);
        }
Пример #22
0
        public static void Main()
        {
            Uri probeEndpointAddress = new Uri("net.tcp://localhost:8001/Probe");
            Uri announcementEndpointAddress = new Uri("net.tcp://localhost:9021/Announcement");

            // Host the DiscoveryProxy service
            ServiceHost proxyServiceHost = new ServiceHost(new DiscoveryProxyService());

            try
            {
                // Add DiscoveryEndpoint to receive Probe and Resolve messages
                DiscoveryEndpoint discoveryEndpoint = new DiscoveryEndpoint(new NetTcpBinding(), new EndpointAddress(probeEndpointAddress));
                discoveryEndpoint.IsSystemEndpoint = false;

                // Add AnnouncementEndpoint to receive Hello and Bye announcement messages
                AnnouncementEndpoint announcementEndpoint = new AnnouncementEndpoint(new NetTcpBinding(), new EndpointAddress(announcementEndpointAddress));

                proxyServiceHost.AddServiceEndpoint(discoveryEndpoint);
                proxyServiceHost.AddServiceEndpoint(announcementEndpoint);

                proxyServiceHost.Open();

                Console.WriteLine("Proxy Service started.");
                Console.WriteLine();
                Console.WriteLine("Press <ENTER> to terminate the service.");
                Console.WriteLine();
                Console.ReadLine();

                proxyServiceHost.Close();
            }
            catch (CommunicationException e)
            {
                Console.WriteLine(e.Message);
            }
            catch (TimeoutException e)
            {
                Console.WriteLine(e.Message);
            }

            if (proxyServiceHost.State != CommunicationState.Closed)
            {
                Console.WriteLine("Aborting the service...");
                proxyServiceHost.Abort();
            }
        }
Пример #23
0
        public static void Main()
        {
            Uri baseAddress = new Uri("net.tcp://localhost:9002/CalculatorService/" + Guid.NewGuid().ToString());
            Uri announcementEndpointAddress = new Uri("net.tcp://localhost:9021/Announcement");

            ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService), baseAddress);
            try
            {
                ServiceEndpoint netTcpEndpoint = serviceHost.AddServiceEndpoint(typeof(ICalculatorService), new NetTcpBinding(), string.Empty);              

                // Create an announcement endpoint, which points to the Announcement Endpoint hosted by the proxy service.
                AnnouncementEndpoint announcementEndpoint = new AnnouncementEndpoint(new NetTcpBinding(), new EndpointAddress(announcementEndpointAddress));
                ServiceDiscoveryBehavior serviceDiscoveryBehavior = new ServiceDiscoveryBehavior();
                serviceDiscoveryBehavior.AnnouncementEndpoints.Add(announcementEndpoint);

                // Make the service discoverable
                serviceHost.Description.Behaviors.Add(serviceDiscoveryBehavior);

                serviceHost.Open();

                Console.WriteLine("Calculator Service started at {0}", baseAddress);
                Console.WriteLine();
                Console.WriteLine("Press <ENTER> to terminate the service.");
                Console.WriteLine();
                Console.ReadLine();

                serviceHost.Close();
            }
            catch (CommunicationException e)
            {
                Console.WriteLine(e.Message);
            }
            catch (TimeoutException e)
            {
                Console.WriteLine(e.Message);
            }   
            
            if (serviceHost.State != CommunicationState.Closed)
            {
                Console.WriteLine("Aborting the service...");
                serviceHost.Abort();
            }
        }
Пример #24
0
		void RunCodeUnderDiscoveryHost1 (Uri serviceUri, Uri dHostUri, Uri aHostUri, Action<Uri,AnnouncementEndpoint,DiscoveryEndpoint> action)
		{
			// announcement service
			var abinding = new CustomBinding (new HttpTransportBindingElement ());
			var aAddress = new EndpointAddress (aHostUri);
			var aEndpoint = new AnnouncementEndpoint (abinding, aAddress);
			
			// discovery service
			var dbinding = new CustomBinding (new HttpTransportBindingElement ());
			var dAddress = new EndpointAddress (dHostUri);
			var dEndpoint = new DiscoveryEndpoint (dbinding, dAddress);
			// Without this, .NET rejects the host as if it had no service.
			dEndpoint.IsSystemEndpoint = false;

			// it internally hosts an AnnouncementService
			using (var inst = new AnnouncementBoundDiscoveryService (aEndpoint)) {
				var host = new ServiceHost (inst);
				host.AddServiceEndpoint (dEndpoint);
				try {
					host.Open ();
					action (serviceUri, aEndpoint, dEndpoint);
				} finally {
					host.Close ();
				}
			}
		}
Пример #25
0
		public AnnouncementClient (AnnouncementEndpoint announcementEndpoint)
		{
		}
Пример #26
0
 public PluginContext(IEnumerable<DiscoverableServiceEndpoint> discoverableServiceEndpoints, AnnouncementEndpoint announcementEndpoint)
 {
     Cancel = false;
     AnnouncementEndpoint = announcementEndpoint;
     DiscoverableServiceEndpoints = discoverableServiceEndpoints ?? new DiscoverableServiceEndpoint[] { };
 }
Пример #27
0
        public void Open(string announcementConnectionUri, int announcementTimerSec, bool enableAnnouncement)
        {
            try
            {
                
                ServiceDiscoveryBehavior serviceDiscoveryBehavior = new ServiceDiscoveryBehavior();

                EndpointDiscoveryBehavior endpointDiscoveryBehavior = new EndpointDiscoveryBehavior();

                XElement endpointMetadata = new XElement("Root", new XElement(_metaDataElement, _metaDataElementValue));
                XElement aliasMetadata = new XElement("Root", new XElement(_metaDataAlias, _metaDataAliasValue));
                XElement LoginMetadata = new XElement("Root", new XElement(_metaDataLogIn, _metaDataLogInValue));

                endpointDiscoveryBehavior.Extensions.Add(endpointMetadata);
                endpointDiscoveryBehavior.Extensions.Add(aliasMetadata);
                endpointDiscoveryBehavior.Extensions.Add(LoginMetadata);

                _netTcpEndpoint.Behaviors.Add(endpointDiscoveryBehavior);

                _serviceHost.Description.Behaviors.Add(serviceDiscoveryBehavior);
                _serviceHost.AddServiceEndpoint(new UdpDiscoveryEndpoint());

                _serviceHost.Open();

                if (enableAnnouncement)
                {
                    Uri announcementEndpointUri = new Uri(announcementConnectionUri);
                    EndpointAddress announcementEndpointAddress = new EndpointAddress(announcementEndpointUri);
                    NetTcpBinding binding = new NetTcpBinding();
                    binding.Security.Mode = SecurityMode.None;
                    _announcementEndpoint = new AnnouncementEndpoint(binding, announcementEndpointAddress);

                    _announcementClient = new AnnouncementClient(_announcementEndpoint);
                    _endpointDiscoveryMetadata = EndpointDiscoveryMetadata.FromServiceEndpoint(_netTcpEndpoint);

                    //Start a timer that send announcement message
                    _announcementTimer = new Timer(announcementTimerSec * 1000);
                    _announcementTimer.AutoReset = true;
                    _announcementTimer.Elapsed += new ElapsedEventHandler(_announcementTimer_Elapsed);
                    _announcementTimer.Start();

                    _announcementClient.Open();
                }

                IsRunning = true;
               
            }
            catch (EndpointNotFoundException ex)
            {
                //this error occurs when announcement endpoint is not on the network
            }
            catch (CommunicationException ex)
            {
                _serviceHost.Abort();
                // customize this exception to be more specific
                throw;
            }
        }
Пример #28
0
		public void UseHttpBinding ()
		{
			var ahost = new ServiceHost (typeof (AnnouncementService));
			var aendpoint = new AnnouncementEndpoint (new CustomBinding (new HttpTransportBindingElement ()), new EndpointAddress ("http://localhost:4989"));
			var ib = new InspectionBehavior ();
			object state = new object ();
			ib.RequestReceived += delegate {
				InspectionBehavior.State = state;
				return null;
			};
			aendpoint.Behaviors.Add (ib);
			ahost.AddServiceEndpoint (aendpoint);
			ahost.Open ();
			try {
				Assert.IsTrue (ib.DispatchBehaviorApplied, "#1");
				var b = new ServiceDiscoveryBehavior ();
				b.AnnouncementEndpoints.Add (new AnnouncementEndpoint (new CustomBinding (new HttpTransportBindingElement ()), new EndpointAddress ("http://localhost:4989")));
				IServiceBehavior sb = b;
				var host = new ServiceHost (typeof (TestService));
				var se = host.AddServiceEndpoint (typeof (ITestService), new BasicHttpBinding (), new Uri ("http://localhost:37564"));

				var bc = new BindingParameterCollection ();
				sb.AddBindingParameters (host.Description, host, host.Description.Endpoints, bc);
				sb.Validate (host.Description, host);
				// ... should "validate" not "apply dispatch behavior" do "add host extension" job? I doubt that.
				var dse = host.Extensions.Find<DiscoveryServiceExtension> ();
				Assert.IsNotNull (dse, "#2");
				sb.ApplyDispatchBehavior (host.Description, host);

				// The IEndpointBehavior from ServiceDiscoveryBehavior, when ApplyDispatchBehavior() is invoked, publishes an endpoint.
				se.Behaviors [0].ApplyDispatchBehavior (se, new EndpointDispatcher (new EndpointAddress ("http://localhost:37564"), "ITestService", "http://tempuri.org/"));

				host.Open ();
				try {
					Assert.AreEqual (state, InspectionBehavior.State, "#3");
				} finally {
					host.Close ();
				}
			} finally {
				ahost.Close ();
			}
		}
        void Initialize(AnnouncementEndpoint announcementEndpoint)
        {
            if (announcementEndpoint.Binding != null && announcementEndpoint.Binding.MessageVersion.Addressing == AddressingVersion.None)
            {
                throw FxTrace.Exception.Argument(
                    "announcementEndpoint",
                    SR.EndpointWithInvalidMessageVersion(
                        announcementEndpoint.GetType().Name,
                        AddressingVersion.None,
                        this.GetType().Name,
                        AddressingVersion.WSAddressing10,
                        AddressingVersion.WSAddressingAugust2004));
            }

            this.innerClient = announcementEndpoint.DiscoveryVersion.Implementation.CreateAnnouncementInnerClient(announcementEndpoint);            
        }