Inheritance: System.ServiceModel.Discovery.DiscoveryEndpoint
Example #1
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 dEndpoint = new UdpDiscoveryEndpoint (DiscoveryVersion.WSDiscovery11, new Uri ("soap.udp://239.255.255.250:3802/"));

		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);
	}
Example #2
0
		public void CanBuildChannelListener ()
		{
			var binding = new UdpDiscoveryEndpoint ().Binding;
			Assert.IsFalse (binding.CanBuildChannelListener<IRequestChannel> (), "#1");
			Assert.IsFalse (binding.CanBuildChannelListener<IRequestSessionChannel> (), "#2");
			Assert.IsTrue (binding.CanBuildChannelListener<IDuplexChannel> (), "#3");
			Assert.IsFalse (binding.CanBuildChannelListener<IDuplexSessionChannel> (), "#4");
			Assert.IsFalse (binding.CanBuildChannelListener<IOutputChannel> (), "#5");
			Assert.IsFalse (binding.CanBuildChannelListener<IOutputSessionChannel> (), "#6");
		}
Example #3
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 dEndpoint = new UdpDiscoveryEndpoint (DiscoveryVersion.WSDiscovery11, new Uri ("soap.udp://239.255.255.250:3802/"));
		// 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 ctx) {
			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 ();
		}
	}
Example #4
0
        public HostDiscovery(Type type)
        {
            m_ContractType = type;

            _udpDiscoveryEndpoint = new UdpDiscoveryEndpoint();

            _lockObject = new object();

            _managedMode = EnableDiscoveryManagedModeEnum.FALSE;

            DiscoveryAdHoc();

            // Change the Default Duration from 20 seconds to 5 Seconds
            m_FindDuration = new TimeSpan(0, 0, 0, 5, 0);
        }
Example #5
0
		public void DefaultValues ()
		{
			var de = new UdpDiscoveryEndpoint ();
			Assert.AreEqual (DiscoveryVersion.WSDiscovery11, de.DiscoveryVersion, "#1");
			Assert.AreEqual (ServiceDiscoveryMode.Adhoc, de.DiscoveryMode, "#2");
			Assert.AreEqual (TimeSpan.FromMilliseconds (500), de.MaxResponseDelay, "#3");
			var cd = de.Contract;
			Assert.IsNotNull (cd, "#11");
			Assert.IsNotNull (de.Binding, "#12");
			TransportBindingElement tbe;
			Assert.IsTrue (de.Binding.CreateBindingElements ().Any (be => (tbe = be as TransportBindingElement) != null && tbe.Scheme == "soap.udp"), "#12-2");
			Assert.IsNotNull (de.Address, "#13");
			Assert.AreEqual (DiscoveryVersion.WSDiscovery11.AdhocAddress, de.Address.Uri, "#13-2");
			Assert.AreEqual (Socket.SupportsIPv4 ? UdpDiscoveryEndpoint.DefaultIPv4MulticastAddress : UdpDiscoveryEndpoint.DefaultIPv6MulticastAddress, de.ListenUri, "#14");
		}
Example #6
0
	static void RunCodeUnderDiscoveryHost (Uri serviceUri, Uri dHostUri, Action<Uri,DiscoveryEndpoint> action)
	{
		var dEndpoint = new UdpDiscoveryEndpoint (DiscoveryVersion.WSDiscoveryApril2005, new Uri ("soap.udp://239.255.255.250:3802/"));
		var ib = new InspectionBehavior ();
		ib.RequestSending += delegate (ref Message msg, IClientChannel channel) {
			var mb = msg.CreateBufferedCopy (0x10000);
			msg = mb.CreateMessage ();
			Console.WriteLine (mb.CreateMessage ());
			return null;
			};
		ib.ReplyReceived += delegate (ref Message msg, object id) {
			var mb = msg.CreateBufferedCopy (0x10000);
			msg = mb.CreateMessage ();
			Console.WriteLine (mb.CreateMessage ());
			}; 
		dEndpoint.Behaviors.Add (ib);

		action (serviceUri, dEndpoint);
	}
Example #7
0
		void RunCodeUnderDiscoveryHost3 (Uri serviceUri, 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 dEndpoint = new UdpDiscoveryEndpoint (DiscoveryVersion.WSDiscovery11, new Uri ("soap.udp://239.255.255.250:3802/"));
			// 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 ();
				}
			}
		}
Example #8
0
        public HostDiscovery(Type type, TimeSpan Duration)
        {
            m_ContractType = type;

            _udpDiscoveryEndpoint = new UdpDiscoveryEndpoint();

            _lockObject = new object();

            _managedMode = EnableDiscoveryManagedModeEnum.FALSE;

            DiscoveryAdHoc();

            m_FindDuration = Duration;
        }
Example #9
0
        public HostDiscovery(Type type, TimeSpan Duration, EnableDiscoveryManagedModeEnum ManagedMode, string DiscoveryProxyUri)
        {
            m_ContractType = type;

            _lockObject = new object();

            _managedMode = ManagedMode;

            if (ManagedMode == EnableDiscoveryManagedModeEnum.TRUE)
            {
                DiscoveryManaged(DiscoveryProxyUri);
            }
            else
            {
                _udpDiscoveryEndpoint = new UdpDiscoveryEndpoint();
                DiscoveryAdHoc();

                //if (ManagedMode == EnableDiscoveryManagedModeEnum.AUTO)
                //{
                //    m_DiscoveryClient.ProxyAvailable += new EventHandler<AnnouncementEventArgs>(m_DiscoveryClient_ProxyAvailable);
                //}
            }
            m_FindDuration = Duration;
        }
Example #10
0
		public void DefaultSettings ()
		{
			var binding = new UdpDiscoveryEndpoint ().Binding;
			Assert.AreEqual (TimeSpan.FromMinutes (1), binding.SendTimeout, "#1");
			Assert.AreEqual (TimeSpan.FromMinutes (10), binding.ReceiveTimeout, "#2");
		}