private static void invokeStartLDC(EndpointAddress hostedEndPoint) { LDCInfo info = new LDCInfo(); info.rate = LDCInfoRate.Item5; info.duration = "30"; using (AccelerationServiceClient client = new AccelerationServiceClient(new InstanceContext(new DiscoveryCallBack()), "AccelerationService")) { // Connect to the discovered service endpoint. client.Endpoint.Address = hostedEndPoint; client.Endpoint.Binding.ReceiveTimeout = new TimeSpan(0, 0, 2); client.Open(); client.StartLDC(info); // Closing the client gracefully closes the connection and cleans up resources. client.Close(); } }
private static void subscribeToLDC(EndpointAddress hostedEndPoint) { Console.WriteLine("Starting subscription event..."); // endpointAddress = StartDiscoveryProcess(false); if (hostedEndPoint != null) { //Get Metadata of the address. // EndpointAddress hostedEndPoint = GetMetaData(endpointAddress); InstanceContext ithis = new InstanceContext(new DiscoveryCallBack()); using (AccelerationServiceClient client = new AccelerationServiceClient(ithis)) { client.Endpoint.Address = hostedEndPoint; client.Open(); EndpointAddress callbackEndpoint = client.InnerDuplexChannel.LocalAddress; EventSourceClient eventSource = new EventSourceClient(ithis, "WSEventing"); eventSource.Endpoint.Address = hostedEndPoint; eventSource.Open(); Subscribe s = new Subscribe(); (s.Delivery = new DeliveryType()).Mode = "http://schemas.xmlsoap.org/ws/2004/08/eventing/DeliveryModes/Push"; XmlDocument doc = new XmlDocument(); using (XmlWriter writer = doc.CreateNavigator().AppendChild()) { EndpointReferenceType notifyTo = new EndpointReferenceType(); (notifyTo.Address = new AttributedURI()).Value = callbackEndpoint.Uri.AbsoluteUri; XmlRootAttribute notifyToElem = new XmlRootAttribute("NotifyTo"); notifyToElem.Namespace = "http://schemas.xmlsoap.org/ws/2004/08/eventing"; XmlDocument doc2 = new XmlDocument(); using (XmlWriter writer2 = doc2.CreateNavigator().AppendChild()) { XmlRootAttribute ReferenceElement = new XmlRootAttribute("ReferenceElement"); foreach (AddressHeader h in callbackEndpoint.Headers) { h.WriteAddressHeader(writer2); } writer2.Close(); notifyTo.ReferenceParameters = new ReferenceParametersType(); notifyTo.ReferenceParameters.Any = notifyTo.ReferenceParameters.Any = doc2.ChildNodes.Cast <XmlElement>().ToArray <XmlElement>(); } new XmlSerializer(notifyTo.GetType(), notifyToElem).Serialize(writer, notifyTo); } (s.Delivery.Any = new XmlElement[1])[0] = doc.DocumentElement; (s.Filter = new FilterType()).Dialect = "http://schemas.xmlsoap.org/ws/2006/02/devprof/Action"; (s.Filter.Any = new System.Xml.XmlNode[1])[0] = new System.Xml.XmlDocument().CreateTextNode("http://www.teco.edu/AccelerationService/AccelerationServiceEventOut"); SubscribeResponse subscription; try { Console.WriteLine("Subscribing to the event..."); //Console.ReadLine(); subscription = eventSource.SubscribeOp(s); } catch (TimeoutException t) { Console.WriteLine("Error reply time out: {0}!!", t.Message); return; } String subscriptionId = null; foreach (XmlNode xel in subscription.SubscriptionManager.ReferenceParameters.Any) { if (xel.LocalName.Equals("Identifier") && xel.NamespaceURI.Equals("http://schemas.xmlsoap.org/ws/2004/08/eventing")) { subscriptionId = xel.InnerText; } } Console.WriteLine("Got subscription: {0}", subscriptionId); Console.WriteLine("Press <ENTER> to unsubscribe."); Console.ReadLine(); Console.WriteLine("Unsubscribing {0}", subscriptionId); SubscriptionManagerClient subscriptionManager = new SubscriptionManagerClient("WSEventingUnsubscribe"); subscriptionManager.Endpoint.Address = hostedEndPoint; subscriptionManager.UnsubscribeOp(subscriptionId, new Unsubscribe()); client.Close(); } } }