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(); } }
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 (); } }
static void RunCodeUnderDiscoveryHost(Uri serviceUri) { // announcement service var aEndpoint = new UdpAnnouncementEndpoint(DiscoveryVersion.WSDiscoveryApril2005, new Uri("soap.udp://239.255.255.250:3802/")); // discovery service var dEndpoint = new UdpDiscoveryEndpoint(DiscoveryVersion.WSDiscoveryApril2005, 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.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(); } }
static void RunCodeUnderDiscoveryHost (Uri serviceUri) { // announcement service var aEndpoint = new UdpAnnouncementEndpoint (DiscoveryVersion.WSDiscoveryApril2005, new Uri ("soap.udp://239.255.255.250:3802/")); // discovery service var dEndpoint = new UdpDiscoveryEndpoint (DiscoveryVersion.WSDiscoveryApril2005, 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.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 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 (); } } }