public WsWsaHeader(String action, String relatesTo, String to, String replyTo, String from, WsXmlNodeList any) { _action = action; _relatesTo = relatesTo; _to = to; if (replyTo != null) { _replyTo = new WsWsaEndpointRef(new System.Uri(replyTo)); } if (from != null) { _from = new WsWsaEndpointRef(new System.Uri(from)); } _any = any; }
internal WsXmlNodeList GetNodes(String localName, String namespaceUri) { WsXmlNodeList list = new WsXmlNodeList(); int count = m_nodeList.Count; WsXmlNode cur; for (int i = 0; i < count; i++) { cur = (WsXmlNode)m_nodeList[i]; if (cur.LocalName == localName && cur.NamespaceURI == namespaceUri) { list.Add(cur); } } return(list); }
public WsWsaEndpointRef(XmlReader reader) { reader.ReadStartElement(); Address = new Uri(reader.ReadElementString("Address", WsWellKnownUri.WsaNamespaceUri_2005_08)); if (reader.IsStartElement("ReferenceProperties", WsWellKnownUri.WsaNamespaceUri_2005_08)) { reader.Read(); #if DEBUG int depth = reader.Depth; #endif RefProperties = new WsXmlNodeList(reader); #if DEBUG Debug.Assert(XmlReaderHelper.HasReadCompleteNode(depth, reader)); #endif reader.ReadEndElement(); } if ( (reader.IsStartElement("ReferenceParameters", WsWellKnownUri.WsaNamespaceUri_2005_08)) || (reader.IsStartElement("ReferenceParameters", WsWellKnownUri.WsaNamespaceUri_2004_08)) ) { reader.Read(); #if DEBUG int depth = reader.Depth; #endif RefParameters = new WsXmlNodeList(reader); #if DEBUG Debug.Assert(XmlReaderHelper.HasReadCompleteNode(depth, reader)); #endif reader.ReadEndElement(); } XmlReaderHelper.SkipAllSiblings(reader); // PortType, ServiceName, xs:any reader.ReadEndElement(); }
internal WsXmlNodeList GetNodes(String localName, String namespaceUri) { WsXmlNodeList list = new WsXmlNodeList(); int count = m_nodeList.Count; WsXmlNode cur; for (int i = 0; i < count; i++) { cur = (WsXmlNode)m_nodeList[i]; if (cur.LocalName == localName && cur.NamespaceURI == namespaceUri) { list.Add(cur); } } return list; }
public MFTestResults XmlTest5_WsXmlNodeList() { /// <summary> /// 1. Verifies the properties of a WsWsaEndpointRefs object /// 2. Adds elements to it /// 3. Re-verifies /// 4. Empties the object /// 5. Re-verifies /// </summary> /// bool testResult = true; try { WsXmlNodeList testWXNs = new WsXmlNodeList(); if (testWXNs.Count != 0) throw new Exception("Count did not set correctly on new"); testWXNs.Add(new WsXmlNode()); WsXmlNode testWXN = new WsXmlNode(); testWXN.LocalName = "testWXN local name"; testWXNs.Add(testWXN); if (testWXNs.Count != 2) throw new Exception("Count did not set correctly on new"); } catch (Exception e) { testResult = false; Log.Comment("Incorrect exception caught: " + e.Message); } return (testResult ? MFTestResults.Pass : MFTestResults.Fail); }
/// <summary> /// Creates an instance of a WsaEndpointRef cless. /// </summary> public WsWsaEndpointRef(Uri address) { Address = address; RefProperties = new WsXmlNodeList(); RefParameters = new WsXmlNodeList(); }
/// <summary> /// Creates an instance of the soap header class. /// </summary> public WsWsaHeader() { _any = new WsXmlNodeList(); }
/// <summary> /// Creates an instance of the soap header class. /// </summary> public WsWsaHeader() { _any = new WsXmlNodeList(); _mustUnderstand = false; }
/// <summary> /// Use to get the status of an event subscription. /// </summary> /// <param name="endpointAddress"> /// A Uri containing the endpoint address of the service or subscription manager that is currently /// maintaining this event subscription on behalf of the device. This address is an http uri /// (i.e. http://ip_address:port/serviceID). /// </param> /// <param name="subscriptionID"> /// A subscription ID returned from a previous subscribe response. The device uses this ID /// to identify a specific event source subscription. /// </param> /// <returns> /// A WsDuration object containing the remaining subscription time for this event subscription, null = infinite. /// </returns> public WsDuration GetStatus(Uri endpointAddress, string subscriptionID) { // Performance debugging DebugTiming timeDebuger = new DebugTiming(); long startTime = timeDebuger.ResetStartTime(""); // Build Renew request using(XmlMemoryWriter xmlWriter = XmlMemoryWriter.Create()) { WsXmlNodeList nodeList = new WsXmlNodeList(); nodeList.Add(new WsXmlNode(WsNamespacePrefix.Wse, "Identifier", null, subscriptionID)); WsWsaHeader header = new WsWsaHeader( m_version.EventingNamespace + "/GetStatus", // Action null, // RelatesTo endpointAddress.AbsoluteUri, // To null, null, nodeList); // ReplyTo, From, Any WsMessage msg = new WsMessage(header, null, WsPrefix.Wse, null, null); WsSoapMessageWriter smw = new WsSoapMessageWriter(m_version); String messageID = smw.WriteSoapMessageStart(xmlWriter, msg); // Performance debuging timeDebuger.PrintElapsedTime("*****Write Header Took"); // write body xmlWriter.WriteStartElement(WsNamespacePrefix.Soap, "Body", null); xmlWriter.WriteStartElement(WsNamespacePrefix.Wse, "GetStatus", null); xmlWriter.WriteString(""); xmlWriter.WriteEndElement(); // End GetStatus // Performance debuging timeDebuger.PrintElapsedTime("*****Write Body Took"); smw.WriteSoapMessageEnd(xmlWriter); // Performance debuging timeDebuger.PrintTotalTime(startTime, "***Renew Message Build Took"); // Create an Http client and send GetStatus request WsHttpClient httpClient = new WsHttpClient(m_version); msg.Body = xmlWriter.ToString(); WsMessage getStatusResponse = httpClient.SendRequest(msg, endpointAddress); // If a GetStatus response is received validate the messageID and action and get the remaining // event subscription time. If a fault is received print exception and go on. if (getStatusResponse == null) { System.Ext.Console.Write(""); System.Ext.Console.Write("Renew response is null."); return null; } else { System.Ext.Console.Write(""); System.Ext.Console.Write("Response From: " + endpointAddress.Host); System.Ext.Console.Write(getStatusResponse.Body as byte[]); // Note: Since the response is the same for GetStatus ans it is for Renew reuse the // Renew response parser. try { return ProcessRenewResponse((byte[])getStatusResponse.Body, messageID); } catch (Exception e) { System.Ext.Console.Write(""); System.Ext.Console.Write("Unsubscribe response parsing failed."); System.Ext.Console.Write(e.Message); } } } return null; }
/// <summary> /// Use to unsubscribe from a devices event source. /// </summary> /// <param name="endpointAddress"> /// A Uri containing the endpoint address of the service or subscription manager that is currently /// maintaining this event subscription on behalf of the device. This address is an http uri /// (i.e. http://ip_address:port/serviceID). /// </param> /// <param name="subscription">An event subscription returned from a previous subscribe call. /// The subscription contains among other things a subscription ID used by the subscription manager /// to identify a specific event source subscription and the endpoint address of the subscription manager. /// </param> /// <returns>True if the Unsubscribe request was successful.</returns> public bool Unsubscribe(Uri endpointAddress, DpwsEventSubscription subscription) { // Performance debugging DebugTiming timeDebuger = new DebugTiming(); long startTime = timeDebuger.ResetStartTime(""); // Build Unsubscribe Request using(XmlMemoryWriter xmlWriter = XmlMemoryWriter.Create()) { WsXmlNodeList nodeList = new WsXmlNodeList(); nodeList.Add(new WsXmlNode(null, "identifier", WsWellKnownUri.WseNamespaceUri, subscription.SubscriptionID)); WsWsaHeader header = new WsWsaHeader( m_version.EventingNamespace + "/Unsubscribe", // Action null, // RelatesTo endpointAddress.AbsoluteUri, // To m_version.AddressingNamespace, // ReplyTo subscription.SubscriptionManager.Address.AbsoluteUri, // From nodeList); // Identifier WsMessage msg = new WsMessage(header, null, WsPrefix.Wse, null, null); WsSoapMessageWriter smw = new WsSoapMessageWriter(m_version); String messageID = smw.WriteSoapMessageStart(xmlWriter, msg); // Performance debuging timeDebuger.PrintElapsedTime("*****Write Header Took"); // write body xmlWriter.WriteStartElement(WsNamespacePrefix.Wse, "Unsubscribe", null); xmlWriter.WriteString(""); xmlWriter.WriteEndElement(); // End Unsubscribe // Performance debuging timeDebuger.PrintElapsedTime("*****Write Body Took"); smw.WriteSoapMessageEnd(xmlWriter); // Performance debuging timeDebuger.PrintTotalTime(startTime, "***Unsubscribe Message Build Took"); // Create an Http client and send Unsubscribe request WsHttpClient httpClient = new WsHttpClient(m_version); msg.Body = xmlWriter.ToArray(); WsMessage unsubscribeResponse = httpClient.SendRequest(msg, endpointAddress); // If a unsubscribe response is received simple validate that the messageID and action are correct and // If a parsing fault is received print exception and go on. if (unsubscribeResponse == null) { System.Ext.Console.Write(""); System.Ext.Console.Write("Unsubscribe response is null."); return false; } else { System.Ext.Console.Write(""); System.Ext.Console.Write("Response From: " + endpointAddress.Host); System.Ext.Console.Write(unsubscribeResponse.Body as byte[]); try { return ProcessUnsubscribeResponse((byte[])unsubscribeResponse.Body, messageID); } catch (Exception e) { System.Ext.Console.Write(""); System.Ext.Console.Write("Unsubscribe response parsing failed."); System.Ext.Console.Write(e.Message); return false; } } } }
/// <summary> /// Use to get the status of an event subscription. /// </summary> /// <param name="endpointAddress"> /// A Uri containing the endpoint address of the service or subscription manager that is currently /// maintaining this event subscription on behalf of the device. This address is an http uri /// (i.e. http://ip_address:port/serviceID). /// </param> /// <param name="subscriptionID"> /// A subscription ID returned from a previous subscribe response. The device uses this ID /// to identify a specific event source subscription. /// </param> /// <returns> /// A WsDuration object containing the remaining subscription time for this event subscription, null = infinite. /// </returns> public WsDuration GetStatus(Uri endpointAddress, string subscriptionID) { // Performance debugging DebugTiming timeDebuger = new DebugTiming(); long startTime = timeDebuger.ResetStartTime(""); // Build Renew request MemoryStream soapStream = new MemoryStream(); XmlWriter xmlWriter = XmlWriter.Create(soapStream); WsXmlNodeList nodeList = new WsXmlNodeList(); nodeList.Add(new WsXmlNode("wse", "Identifier", null, subscriptionID)); WsWsaHeader header = new WsWsaHeader( WsWellKnownUri.WseNamespaceUri + "/GetStatus", // Action null, // RelatesTo endpointAddress.AbsoluteUri, // To null, null, nodeList); // ReplyTo, From, Any String messageID = WsSoapMessageWriter.WriteSoapMessageStart(xmlWriter, WsSoapMessageWriter.Prefixes.Wse, null, header, null); // Performance debuging timeDebuger.PrintElapsedTime("*****Write Header Took"); // write body xmlWriter.WriteStartElement("soap", "Body", null); xmlWriter.WriteStartElement("wse", "GetStatus", null); xmlWriter.WriteString(""); xmlWriter.WriteEndElement(); // End GetStatus // Performance debuging timeDebuger.PrintElapsedTime("*****Write Body Took"); WsSoapMessageWriter.WriteSoapMessageEnd(xmlWriter); // Performance debuging timeDebuger.PrintTotalTime(startTime, "***Renew Message Build Took"); // Flush and close writer xmlWriter.Flush(); xmlWriter.Close(); // Create an Http client and send GetStatus request WsHttpClient httpClient = new WsHttpClient(); byte[] getStatusResponse = null; try { getStatusResponse = httpClient.SendRequest(soapStream.ToArray(), endpointAddress.ToString(), false, false); } catch (Exception e) { System.Ext.Console.Write(""); System.Ext.Console.Write("GetStatus failed. " + e.Message); return null; } // If a GetStatus response is received validate the messageID and action and get the remaining // event subscription time. If a fault is received print exception and go on. if (getStatusResponse == null) { System.Ext.Console.Write(""); System.Ext.Console.Write("Renew response is null."); return null; } else { System.Ext.Console.Write(""); System.Ext.Console.Write("Response From: " + endpointAddress.Host); System.Ext.Console.Write(new String(System.Text.Encoding.UTF8.GetChars(getStatusResponse))); // Note: Since the response is the same for GetStatus ans it is for Renew reuse the // Renew response parser. try { return ProcessRenewResponse(getStatusResponse, messageID); } catch (Exception e) { System.Ext.Console.Write(""); System.Ext.Console.Write("Unsubscribe response parsing failed."); System.Ext.Console.Write(e.Message); } } return null; }
/// <summary> /// Use to unsubscribe from a devices event source. /// </summary> /// <param name="endpointAddress"> /// A Uri containing the endpoint address of the service or subscription manager that is currently /// maintaining this event subscription on behalf of the device. This address is an http uri /// (i.e. http://ip_address:port/serviceID). /// </param> /// <param name="subscription">An event subscription returned from a previous subscribe call. /// The subscription contains among other things a subscription ID used by the subscription manager /// to identify a specific event source subscription and the endpoint address of the subscription manager. /// </param> /// <returns>True if the Unsubscribe request was successful.</returns> public bool Unsubscribe(Uri endpointAddress, DpwsEventSubscription subscription) { // Performance debugging DebugTiming timeDebuger = new DebugTiming(); long startTime = timeDebuger.ResetStartTime(""); // Build Unsubscribe Request MemoryStream soapStream = new MemoryStream(); XmlWriter xmlWriter = XmlWriter.Create(soapStream); WsXmlNodeList nodeList = new WsXmlNodeList(); nodeList.Add(new WsXmlNode(null, "identifier", WsWellKnownUri.WseNamespaceUri, subscription.SubscriptionID)); WsWsaHeader header = new WsWsaHeader( WsWellKnownUri.WseNamespaceUri + "/Unsubscribe", // Action null, // RelatesTo endpointAddress.AbsoluteUri, // To WsWellKnownUri.WsaAnonymousUri, // ReplyTo subscription.SubscriptionManager.Address.AbsoluteUri, // From nodeList); // Identifier String messageID = WsSoapMessageWriter.WriteSoapMessageStart(xmlWriter, WsSoapMessageWriter.Prefixes.Wse, null, header, null); // Performance debuging timeDebuger.PrintElapsedTime("*****Write Header Took"); // write body xmlWriter.WriteStartElement("wse", "Unsubscribe", null); xmlWriter.WriteString(""); xmlWriter.WriteEndElement(); // End Unsubscribe // Performance debuging timeDebuger.PrintElapsedTime("*****Write Body Took"); WsSoapMessageWriter.WriteSoapMessageEnd(xmlWriter); // Performance debuging timeDebuger.PrintTotalTime(startTime, "***Unsubscribe Message Build Took"); // Flush and close writer xmlWriter.Flush(); xmlWriter.Close(); // Create an Http client and send Unsubscribe request WsHttpClient httpClient = new WsHttpClient(); byte[] unsubscribeResponse = null; try { unsubscribeResponse = httpClient.SendRequest(soapStream.ToArray(), endpointAddress.ToString(), false, false); } catch (Exception e) { System.Ext.Console.Write(""); System.Ext.Console.Write("Unsubscribe failed. " + e.Message); return false; } // If a unsubscribe response is received simple validate that the messageID and action are correct and // If a parsing fault is received print exception and go on. if (unsubscribeResponse == null) { System.Ext.Console.Write(""); System.Ext.Console.Write("Unsubscribe response is null."); return false; } else { System.Ext.Console.Write(""); System.Ext.Console.Write("Response From: " + endpointAddress.Host); System.Ext.Console.Write(new String(System.Text.Encoding.UTF8.GetChars(unsubscribeResponse))); try { return ProcessUnsubscribeResponse(unsubscribeResponse, messageID); } catch (Exception e) { System.Ext.Console.Write(""); System.Ext.Console.Write("Unsubscribe response parsing failed."); System.Ext.Console.Write(e.Message); return false; } } }
/// <summary> /// Creates an instance of the soap header class. /// </summary> public WsWsaHeader() { _any = new WsXmlNodeList(); _flags = WsMessageFlags.None; }