Example #1
0
        private static void invokeStartDownload(EndpointAddress hostedEndPoint)
        {
            using (DataLoggingServiceClient client =
                       new DataLoggingServiceClient(new InstanceContext(new DiscoveryCallBack()), "DataLoggingService"))
            {
                // Connect to the discovered service endpoint.
                client.Endpoint.Address = hostedEndPoint;
                client.Endpoint.Binding.ReceiveTimeout = new TimeSpan(0, 0, 2);
                client.Open();

                client.StartDownload();

                // Closing the client gracefully closes the connection and cleans up resources.
                client.Close();
            }
        }
Example #2
0
        private static void invokeGetSessions(EndpointAddress hostedEndPoint)
        {
            using (DataLoggingServiceClient client =
                       new DataLoggingServiceClient(new InstanceContext(new DiscoveryCallBack()), "DataLoggingService"))
            {
                // Connect to the discovered service endpoint.
                client.Endpoint.Address = hostedEndPoint;
                client.Endpoint.Binding.ReceiveTimeout = new TimeSpan(0, 0, 2);
                client.Open();

                SessionInfo info = client.GetSessionCount();
                Console.WriteLine("Session Count: {0}", info.count);

                // Closing the client gracefully closes the connection and cleans up resources.
                client.Close();
            }
        }
Example #3
0
        private static void subscribeToDownload(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 (DataLoggingServiceClient client = new DataLoggingServiceClient(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/DataLoggingService/DataLoggingServiceEventOut");

                    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();
                }
            }
        }