static void RunCodeUnderDiscoveryHost (Uri serviceUri, Uri dHostUri, Action<Uri,AnnouncementEndpoint,DiscoveryEndpoint> action) { var aEndpoint = new UdpAnnouncementEndpoint (DiscoveryVersion.WSDiscoveryApril2005, new Uri ("soap.udp://239.255.255.250:3802/")); var dbinding = new CustomBinding (new HttpTransportBindingElement ()); var dAddress = new EndpointAddress (dHostUri); var dEndpoint = new DiscoveryEndpoint (dbinding, dAddress); 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); }
public static void Main () { var uri = new Uri ("soap.udp://239.255.255.250:3802"); for (int i = 0; i < 2; i++) { var binding = new UdpAnnouncementEndpoint (uri).Binding; IFooChannel proxy = new ChannelFactory<IFooChannel> ( binding, new EndpointAddress (uri) ).CreateChannel (); proxy.Open (); proxy.SendMsg ("TEST FOR ECHO"); } }
public void DefaultValues () { var de = new UdpAnnouncementEndpoint (); Assert.AreEqual (DiscoveryVersion.WSDiscovery11, de.DiscoveryVersion, "#1"); Assert.AreEqual (TimeSpan.FromMilliseconds (500), 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.IsNotNull (de.Binding, "#12"); TransportBindingElement tbe = null; 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 ? UdpAnnouncementEndpoint.DefaultIPv4MulticastAddress : UdpAnnouncementEndpoint.DefaultIPv6MulticastAddress, de.ListenUri, "#14"); }
public static void Main () { ServiceHost host = new ServiceHost (typeof (Foo)); var uri = new Uri ("soap.udp://239.255.255.250:3802"); var binding = new UdpAnnouncementEndpoint (uri).Binding; binding.ReceiveTimeout = TimeSpan.FromSeconds (5); binding.OpenTimeout = TimeSpan.FromSeconds (20); host.AddServiceEndpoint ("IFoo", binding, uri); host.Description.Behaviors.Find<ServiceBehaviorAttribute> () .IncludeExceptionDetailInFaults = true; host.Open (); Console.WriteLine ("Hit [CR] key to close ..."); Console.ReadLine (); host.Close (); }
public void DefaultValues () { var de = new UdpAnnouncementEndpoint (); Assert.AreEqual (DiscoveryVersion.WSDiscovery11, de.DiscoveryVersion, "#1"); Assert.AreEqual (TimeSpan.FromMilliseconds (500), 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.IsNotNull (de.Binding, "#12"); TransportBindingElement tbe = null; 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 ? UdpAnnouncementEndpoint.DefaultIPv4MulticastAddress : UdpAnnouncementEndpoint.DefaultIPv6MulticastAddress, de.ListenUri, "#14"); // .NET has two endpoint behaviors: DiscoveryViaBehavior and UdpContractFilterBehavior. Not worthy of testing that though. // Assert.AreEqual (2, de.Behaviors.Count, "#15"); // foreach (var eb in de.Behaviors) Console.Error.WriteLine (eb); }
static void RunCodeUnderDiscoveryHost (Uri serviceUri, Uri dHostUri) { // announcement service var aEndpoint = new UdpAnnouncementEndpoint (DiscoveryVersion.WSDiscoveryApril2005, new Uri ("soap.udp://239.255.255.250:3802/")); // 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; 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); // 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 (); } }
void RunCodeUnderDiscoveryHost2 (Uri serviceUri, Uri dHostUri, Action<Uri,AnnouncementEndpoint,DiscoveryEndpoint> action) { // announcement service var aEndpoint = new UdpAnnouncementEndpoint (new Uri ("soap.udp://239.255.255.250:3802/")); // 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 (); } } }