public void FireSimpleEvent(int a) { DpwsWseEventSource eventSource = this.EventSources["SimpleEvent"]; WsWsaHeader header = new WsWsaHeader(c_namespaceUri + "/SimpleEvent", null, null, null, null, null); Device.SubscriptionManager.FireEvent(this, // hosted service eventSource, header, BuildSimpleEventMessageBody(a) ); Debug.Print("Simple event was fired with param a=" + a + "."); }
// This method is called by the timer delegate periodically to send events public void SendEvent(Object stateInfo) { if (rentryFlag == true) // prevent this method from running concurrently with itself { return; } rentryFlag = true; // Fire SimpleEvent try { DpwsWseEventSource eventSource = m_hostedService.EventSources["SimpleEvent"]; WsWsaHeader header = new WsWsaHeader("http://schemas.example.org/EventingService/SimpleEvent", null, null, null, null, null); WsMessage msg = new WsMessage(header, null, WsPrefix.Wse); msg.Body = System.Text.UTF8Encoding.UTF8.GetBytes(BuildSimpleEventMessage(m_hostedService)); Device.SubscriptionManager.FireEvent(m_hostedService, eventSource, msg); } catch { //Log.Comment(""); //Log.Comment("SimpleEvent FireEvent failed: " + e.Message); //Log.Comment(""); rentryFlag = false; } // Fire IntegerEvent try { DpwsWseEventSource eventSource = m_hostedService.EventSources["IntegerEvent"]; WsWsaHeader header = new WsWsaHeader("http://schemas.example.org/EventingService/IntegerEvent", null, null, null, null, null); WsMessage msg = new WsMessage(header, null, WsPrefix.Wse); msg.Body = System.Text.UTF8Encoding.UTF8.GetBytes(BuildIntegerEventMessage(m_hostedService)); Device.SubscriptionManager.FireEvent(m_hostedService, eventSource, msg); } catch { //Log.Comment(""); //Log.Comment("IntegerEvent FireEvent failed: " + e.Message); //Log.Comment(""); rentryFlag = false; } rentryFlag = false; }
public MFTestResults ServicesTest3_DpwsWseEventSource() { /// <summary> /// 1. Gets and verifies each of the properties of a DpwsWseEventSource object /// 2. Sets and re-verifies all properties /// </summary> /// bool testResult = true; try { DpwsWseEventSource testDWES = new DpwsWseEventSource( "testPrefix", "urn:uuid:3cb0d1ba-cc3a-46ce-b416-212ac2419b51", "testName"); if (testDWES.Name == null || testDWES.Name.GetType() != Type.GetType("System.String") || testDWES.Name != "testName") { throw new Exception("Name did not set correctly"); } if (testDWES.NamespaceURI == null || testDWES.NamespaceURI.GetType() != Type.GetType("System.String") || testDWES.NamespaceURI != "urn:uuid:3cb0d1ba-cc3a-46ce-b416-212ac2419b51") { throw new Exception("NamespaceURI did not set correctly"); } if (testDWES.Operation == null || testDWES.Operation.GetType() != Type.GetType("System.String") || testDWES.Operation != "urn:uuid:3cb0d1ba-cc3a-46ce-b416-212ac2419b51" + "/testName") { throw new Exception("Operation did not set correctly"); } if (testDWES.Prefix == null || testDWES.Prefix.GetType() != Type.GetType("System.String") || testDWES.Prefix != "testPrefix") { throw new Exception("Prefix did not set correctly"); } } catch (Exception e) { testResult = false; Log.Comment("Incorrect exception caught: " + e.Message); } return(testResult ? MFTestResults.Pass : MFTestResults.Fail); }
// Constructor sets service properties and defines operations and adds event sources public SimpleService(ProtocolVersion version) : base(version) { // Add ServiceNamespace. Set ServiceID and ServiceTypeName ServiceNamespace = new WsXmlNamespace("sim", "http://schemas.example.org/SimpleService"); ServiceID = "urn:uuid:3cb0d1ba-cc3a-46ce-b416-212ac2419b90"; ServiceTypeName = "SimpleService"; // Add service operations ServiceOperations.Add(new WsServiceOperation("http://schemas.example.org/SimpleService", "OneWay")); ServiceOperations.Add(new WsServiceOperation("http://schemas.example.org/SimpleService", "TwoWayRequest")); // Add event sources DpwsWseEventSource SimpleEvent = new DpwsWseEventSource("sim", "http://schemas.example.org/EventingService", "SimpleEvent"); EventSources.Add(SimpleEvent); this.AddEventServices(); }
public EventingService() { // The client filters devices when probing using the ServiceTypeName property this.ServiceTypeName = "EventingServiceType"; // Add a unique namespace for our service this.ServiceNamespace = new WsXmlNamespace("eventing", // prefix c_namespaceUri); // URI // Unique ID to access the service this.ServiceID = "urn:uuid:93252386-0724-c8ca-bd31-000000732d93"; // Add event source DpwsWseEventSource eventSource = new DpwsWseEventSource(this.ServiceNamespace.Prefix, this.ServiceNamespace.NamespaceURI, "SimpleEvent"); // event name this.EventSources.Add(eventSource); }
public TestService(string guid, ProtocolVersion version) : base(version) { // Add ServiceNamespace. Set ServiceID and ServiceTypeName ServiceNamespace = new WsXmlNamespace("sim", "http://schemas.example.org/SimpleService"); ServiceID = "urn:uuid:" + guid; ServiceTypeName = "TestService"; // Add additional namesapces if needed // example: Namespaces.Add("someprefix", "http://some/Namespace"); // Add service operations ServiceOperations.Add(new WsServiceOperation("http://schemas.example.org/SimpleService", "OneWay")); ServiceOperations.Add(new WsServiceOperation("http://schemas.example.org/SimpleService", "TwoWayRequest")); // Add event sources DpwsWseEventSource SimpleEvent = new DpwsWseEventSource("sim", "http://schemas.example.org/EventingService", "SimpleEvent"); EventSources.Add(SimpleEvent); this.AddEventServices(); }