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); }
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); }
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); }
static void RunCodeUnderDiscoveryHost(Uri serviceUri, Action <Uri, DiscoveryEndpoint> action) { var dBinding = new CustomBinding(new TextMessageEncodingBindingElement(), new TcpTransportBindingElement()); var dEndpoint = new DiscoveryEndpoint(DiscoveryVersion.WSDiscovery11, ServiceDiscoveryMode.Adhoc, dBinding, new EndpointAddress("net.tcp://" + hostname + ":9090/")); 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()); }; 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); }; dEndpoint.Behaviors.Add(ib); action(serviceUri, dEndpoint); }
static void Main(string[] args) { for (Type t = typeof (MyApp.Common.ServiceResult<string>); t != null; t = t.BaseType) foreach (var fi in t.GetFields (BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) Console.WriteLine (fi); Type iserviceType = typeof(ITestApplication); Type serviceType = typeof(TestApplication); string baseAddress = "http://localhost:4321/"; ServiceHost host = new ServiceHost(serviceType, new Uri[] { new Uri(baseAddress) }); var se = host.AddServiceEndpoint(iserviceType, new BasicHttpBinding(), serviceType.Name); var ib = new InspectionBehavior (); ib.RequestReceived += delegate (ref Message msg, IClientChannel channel, InstanceContext instanceContext) { var mb = msg.CreateBufferedCopy (0x10000); msg = mb.CreateMessage (); Console.WriteLine (mb.CreateMessage ()); return null; }; ib.ReplySending += delegate (ref Message msg, object state) { var mb = msg.CreateBufferedCopy (0x10000); msg = mb.CreateMessage (); Console.WriteLine (mb.CreateMessage ()); }; se.Behaviors.Add (ib); host.Open(); Console.WriteLine("Service published:\n"); Console.WriteLine(baseAddress + serviceType.Name); Console.Out.WriteLine("\n--- Press <return> to quit ---\n"); Console.ReadLine(); System.Environment.Exit(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(); } }
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 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); }
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); }
static void RunCodeUnderDiscoveryHost (Uri serviceUri, Uri dHostUri, Action<Uri,DiscoveryEndpoint> action) { var dbinding = new CustomBinding (new HttpTransportBindingElement ()); var dAddress = new EndpointAddress (dHostUri); var dEndpoint = new DiscoveryEndpoint (dbinding, dAddress); 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); }
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, Uri dHostUri, Action <Uri, DiscoveryEndpoint> action) { var dbinding = new CustomBinding(new HttpTransportBindingElement()); var dAddress = new EndpointAddress(dHostUri); var dEndpoint = new DiscoveryEndpoint(dbinding, dAddress); 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); }
static void Main(string[] args) { for (Type t = typeof(MyApp.Common.ServiceResult <string>); t != null; t = t.BaseType) { foreach (var fi in t.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) { Console.WriteLine(fi); } } Type iserviceType = typeof(ITestApplication); Type serviceType = typeof(TestApplication); string baseAddress = "http://localhost:4321/"; ServiceHost host = new ServiceHost(serviceType, new Uri[] { new Uri(baseAddress) }); var se = host.AddServiceEndpoint(iserviceType, new BasicHttpBinding(), serviceType.Name); var ib = new InspectionBehavior(); ib.RequestReceived += delegate(ref Message msg, IClientChannel channel, InstanceContext instanceContext) { var mb = msg.CreateBufferedCopy(0x10000); msg = mb.CreateMessage(); Console.WriteLine(mb.CreateMessage()); return(null); }; ib.ReplySending += delegate(ref Message msg, object state) { var mb = msg.CreateBufferedCopy(0x10000); msg = mb.CreateMessage(); Console.WriteLine(mb.CreateMessage()); }; se.Behaviors.Add(ib); host.Open(); Console.WriteLine("Service published:\n"); Console.WriteLine(baseAddress + serviceType.Name); Console.Out.WriteLine("\n--- Press <return> to quit ---\n"); Console.ReadLine(); System.Environment.Exit(0); }
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 (); } }
/// <summary> /// Constructor allowing for a custom serializer and additional parameterized data /// </summary> /// <param name="serializer"></param> /// <param name="additionalData"></param> /// <param name="behavior"></param> public HypermediaGenerator(JsonSerializer serializer, Dictionary <string, string> additionalData, InspectionBehavior behavior = InspectionBehavior.Strict) { this.Serializer = serializer; this.valueCache = additionalData; this.InspectionBehavior = behavior; }
/// <summary> /// Constructor allowing for a custom Json serializer to be used /// </summary> /// <param name="serializer"></param> /// <param name="behavior"></param> public HypermediaGenerator(JsonSerializer serializer, InspectionBehavior behavior = InspectionBehavior.Strict) { this.Serializer = serializer; valueCache = new Dictionary <string, string>(); this.InspectionBehavior = behavior; }