/// <summary> /// Shows the values. /// </summary> /// <param name="response">The response.</param> public static void ShowValues(SSimpSample response) { Console.WriteLine("Results:"); if (response.Accelleration != null) { Console.WriteLine("\tAcceleration X: {0}", response.Accelleration.x); Console.WriteLine("\tAcceleration Y: {0}", response.Accelleration.y); Console.WriteLine("\tAcceleration Z: {0}", response.Accelleration.z); } if (response.Audio != null) { Console.WriteLine("\tAudio: {0}", response.Audio.volume); } if (response.Force != null) { Console.WriteLine("\tForce: {0}", response.Force.value); } if (response.Light != null) { Console.WriteLine("\tLight: {0}", response.Light.infrared); } if (response.Temperature != null) { Console.WriteLine("\tTemperature: {0}", response.Temperature.value); } }
void InvokeService(EndpointAddress endpointAddress) { InstanceContext ithis = new InstanceContext(this); String callbackEndpoint = "http://vs2010test/blub"; // Create a client SensorValuesClient client = new SensorValuesClient(new InstanceContext(this)); client.Endpoint.Address = endpointAddress; // callbackEndpoint=client.InnerChannel.LocalAddress.Uri.AbsoluteUri; callbackEndpoint = client.InnerDuplexChannel.LocalAddress.Uri.AbsoluteUri; Console.WriteLine("Invoking at {0}", endpointAddress); // client.GetSensorValues(out accelleration,out audio,out light,out force,out temperature); SSimpSample response = client.GetSensorValues(); Console.WriteLine("Got response: {0}", response); Console.WriteLine("Subscribing event {1} at {0}", endpointAddress, "http://www.teco.edu/SensorValues/SensorValuesEventOut"); EventSourceClient eventSource = new EventSourceClient(ithis); eventSource.Endpoint.Address = endpointAddress; SubscribeOpRequest s = new SubscribeOpRequest(); s.Subscribe = new Subscribe(); (s.Subscribe.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; XmlRootAttribute notifyToElem = new XmlRootAttribute("NotifyTo"); notifyToElem.Namespace = "http://schemas.xmlsoap.org/ws/2004/08/eventing"; new XmlSerializer(notifyTo.GetType(), notifyToElem).Serialize(writer, notifyTo); } (s.Subscribe.Delivery.Any = new XmlElement[1])[0] = doc.DocumentElement; (s.Subscribe.Filter = new FilterType()).Dialect = "http://schemas.xmlsoap.org/ws/2006/02/devprof/Action"; (s.Subscribe.Filter.Any = new System.Xml.XmlNode[1]) [0] = new System.Xml.XmlDocument().CreateTextNode("http://www.teco.edu/SensorValues/SensorValuesEventOut"); SubscribeOpResponse subscription; try { Console.WriteLine("Press <ENTER> to subscribe."); Console.ReadLine(); subscription = eventSource.SubscribeOp(s); } catch (TimeoutException t) { Console.WriteLine("Error reply time out: {0}!!", t.Message); return; } // eventSource.Close(); String subscriptionId = null; foreach (XmlNode xel in subscription.SubscribeResponse.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(); UnsubscribeOpRequest unsubscribe = new UnsubscribeOpRequest(); unsubscribe.Identifier = subscriptionId; Console.WriteLine("Unsubscribing {0}", subscriptionId); SubscriptionManagerClient subscriptionManager = new SubscriptionManagerClient(); subscriptionManager.Endpoint.Address = endpointAddress; subscriptionManager.UnsubscribeOp(unsubscribe); //Closing the client gracefully closes the connection and cleans up resources //client.Close(); }