/// <summary> /// Use to request metadata from a devices hosted service endpoint. /// </summary> /// <param name="serviceAddress"> /// A string containing the transport address of a service endpoint. For Dpws the address represents /// a devices transport address. /// For example: http://192.168.0.1:8084/3cb0d1ba-cc3a-46ce-b416-212ac2419b20 /// </param> /// <returns> /// A collection of DpwsMetadata objects containing endpoint details about services hosted by a device. /// </returns> public DpwsMetadata Get(string serviceAddress) { // Convert the address string to a Uri Uri serviceUri = null; try { serviceUri = new Uri(serviceAddress); if (serviceUri.Scheme != "http") { System.Ext.Console.Write(""); System.Ext.Console.Write("Invalid serviceAddress. Must be a Uri. Http Uri schemes only."); System.Ext.Console.Write(""); return null; } } catch (Exception e) { System.Ext.Console.Write(""); System.Ext.Console.Write(e.Message); System.Ext.Console.Write(""); return null; } // Performance debugging DebugTiming timeDebuger = new DebugTiming(); long startTime = timeDebuger.ResetStartTime(""); // Build Get Request MemoryStream soapStream = new MemoryStream(); XmlWriter xmlWriter = XmlWriter.Create(soapStream); WsWsaHeader header = new WsWsaHeader( WsWellKnownUri.WstNamespaceUri + "/Get", // Action null, // RelatesTo "urn:uuid:" + serviceUri.AbsolutePath.Substring(1), // To WsWellKnownUri.WsaAnonymousUri, // ReplyTo null, null); // From, Any String messageID = WsSoapMessageWriter.WriteSoapMessageStart(xmlWriter, WsSoapMessageWriter.Prefixes.None, null, header, null); // Performance debuging timeDebuger.PrintElapsedTime("*****Write Header Took"); // Performance debuging timeDebuger.PrintElapsedTime("*****Write Body Took"); WsSoapMessageWriter.WriteSoapMessageEnd(xmlWriter); // Performance debuging timeDebuger.PrintTotalTime(startTime, "***Get Message Build Took"); // Flush and close writer xmlWriter.Flush(); xmlWriter.Close(); // Create an Http client and send Get request WsHttpClient httpClient = new WsHttpClient(); byte[] getResponse = null; try { System.Ext.Console.Write(""); System.Ext.Console.Write("Sending Get to: " + serviceAddress); getResponse = httpClient.SendRequest(soapStream.ToArray(), serviceAddress, false, false); } catch (Exception e) { System.Ext.Console.Write(""); System.Ext.Console.Write("Get failed. " + e.Message); return null; } // If a get response is received process it and return DpwsMetadata object DpwsMetadata metadata = null; if (getResponse == null) return null; else { System.Ext.Console.Write(new String(System.Text.Encoding.UTF8.GetChars(getResponse))); System.Ext.Console.Write(""); DpwsDiscoClientProcessor soapProcessor = new DpwsDiscoClientProcessor(); try { metadata = soapProcessor.ProcessGetResponse(getResponse, messageID); } catch (Exception e) { System.Ext.Console.Write(""); System.Ext.Console.Write("Get response parser threw an exception. " + e.Message); return null; } } return metadata; }
/// <summary> /// Use to request metadata from a devices hosted service endpoint. /// </summary> /// <param name="serviceAddress"> /// A string containing the transport address of a service endpoint. For Dpws the address represents /// a devices transport address. /// For example: http://192.168.0.1:8084/3cb0d1ba-cc3a-46ce-b416-212ac2419b20 /// </param> /// <returns> /// A collection of DpwsMetadata objects containing endpoint details about services hosted by a device. /// </returns> public DpwsMetadata Get(string serviceAddress) { // Convert the address string to a Uri Uri serviceUri = null; try { serviceUri = new Uri(serviceAddress); if (serviceUri.Scheme != "http") { System.Ext.Console.Write(""); System.Ext.Console.Write("Invalid serviceAddress. Must be a Uri. Http Uri schemes only."); System.Ext.Console.Write(""); return(null); } } catch (Exception e) { System.Ext.Console.Write(""); System.Ext.Console.Write(e.Message); System.Ext.Console.Write(""); return(null); } // Performance debugging DebugTiming timeDebuger = new DebugTiming(); long startTime = timeDebuger.ResetStartTime(""); // Build Get Request MemoryStream soapStream = new MemoryStream(); XmlWriter xmlWriter = XmlWriter.Create(soapStream); WsWsaHeader header = new WsWsaHeader( WsWellKnownUri.WstNamespaceUri + "/Get", // Action null, // RelatesTo "urn:uuid:" + serviceUri.AbsolutePath.Substring(1), // To WsWellKnownUri.WsaAnonymousUri, // ReplyTo null, null); // From, Any String messageID = WsSoapMessageWriter.WriteSoapMessageStart(xmlWriter, WsSoapMessageWriter.Prefixes.None, null, header, null); // Performance debuging timeDebuger.PrintElapsedTime("*****Write Header Took"); // Performance debuging timeDebuger.PrintElapsedTime("*****Write Body Took"); WsSoapMessageWriter.WriteSoapMessageEnd(xmlWriter); // Performance debuging timeDebuger.PrintTotalTime(startTime, "***Get Message Build Took"); // Flush and close writer xmlWriter.Flush(); xmlWriter.Close(); // Create an Http client and send Get request WsHttpClient httpClient = new WsHttpClient(); byte[] getResponse = null; try { System.Ext.Console.Write(""); System.Ext.Console.Write("Sending Get to: " + serviceAddress); getResponse = httpClient.SendRequest(soapStream.ToArray(), serviceAddress, false, false); } catch (Exception e) { System.Ext.Console.Write(""); System.Ext.Console.Write("Get failed. " + e.Message); return(null); } // If a get response is received process it and return DpwsMetadata object DpwsMetadata metadata = null; if (getResponse == null) { return(null); } else { System.Ext.Console.Write(new String(System.Text.Encoding.UTF8.GetChars(getResponse))); System.Ext.Console.Write(""); DpwsDiscoClientProcessor soapProcessor = new DpwsDiscoClientProcessor(); try { metadata = soapProcessor.ProcessGetResponse(getResponse, messageID); } catch (Exception e) { System.Ext.Console.Write(""); System.Ext.Console.Write("Get response parser threw an exception. " + e.Message); return(null); } } return(metadata); }
/// <summary> /// Use to request metadata from a devices hosted service endpoint. /// </summary> /// <param name="serviceAddress"> /// A string containing the transport address of a service endpoint. For Dpws the address represents /// a devices transport address. /// For example: http://192.168.0.1:8084/3cb0d1ba-cc3a-46ce-b416-212ac2419b20 /// </param> /// <returns> /// A collection of DpwsMetadata objects containing endpoint details about services hosted by a device. /// </returns> public DpwsMetadata Get(string serviceAddress) { // Convert the address string to a Uri Uri serviceUri = null; try { serviceUri = new Uri(serviceAddress); if (serviceUri.Scheme != "http") { System.Ext.Console.Write(""); System.Ext.Console.Write("Invalid serviceAddress. Must be a Uri. Http Uri schemes only."); System.Ext.Console.Write(""); return null; } } catch (Exception e) { System.Ext.Console.Write(""); System.Ext.Console.Write(e.Message); System.Ext.Console.Write(""); return null; } // Performance debugging DebugTiming timeDebuger = new DebugTiming(); long startTime = timeDebuger.ResetStartTime(""); // Build Get Request using(XmlMemoryWriter xmlWriter = XmlMemoryWriter.Create()) { WsWsaHeader header = new WsWsaHeader( WsWellKnownUri.WstNamespaceUri + "/Get", // Action null, // RelatesTo "urn:uuid:" + serviceUri.AbsolutePath.Substring(1), // To //TODO: should be ROLE??? m_version.AnonymousRoleUri, // ReplyTo null, null); // From, Any WsMessage msg = new WsMessage(header, null, WsPrefix.None, null, null); WsSoapMessageWriter smw = new WsSoapMessageWriter(m_version); String messageID = smw.WriteSoapMessageStart(xmlWriter, msg); // Performance debuging timeDebuger.PrintElapsedTime("*****Write Header Took"); // Performance debuging timeDebuger.PrintElapsedTime("*****Write Body Took"); smw.WriteSoapMessageEnd(xmlWriter); // Performance debuging timeDebuger.PrintTotalTime(startTime, "***Get Message Build Took"); // Create an Http client and send Get request WsHttpClient httpClient = new WsHttpClient(m_version); System.Ext.Console.Write(""); System.Ext.Console.Write("Sending Get to: " + serviceAddress); msg.Body = xmlWriter.ToArray(); WsMessage getResponse = httpClient.SendRequest(msg, new Uri(serviceAddress)); // If a get response is received process it and return DpwsMetadata object DpwsMetadata metadata = null; if (getResponse == null || getResponse.Body == null) { return null; } else { DpwsDiscoClientProcessor soapProcessor = new DpwsDiscoClientProcessor(m_version); try { System.Ext.Console.Write(getResponse.Body as byte[]); System.Ext.Console.Write(""); metadata = soapProcessor.ProcessGetResponse((byte[])getResponse.Body, messageID); } catch (Exception e) { System.Ext.Console.Write(""); System.Ext.Console.Write("Get response parser threw an exception. " + e.Message); return null; } } return metadata; } }
/// <summary> /// Use to request metadata from a devices hosted service endpoint. /// </summary> /// <param name="serviceAddress"> /// A string containing the transport address of a service endpoint. For Dpws the address represents /// a devices transport address. /// For example: http://192.168.0.1:8084/3cb0d1ba-cc3a-46ce-b416-212ac2419b20 /// </param> /// <returns> /// A collection of DpwsMetadata objects containing endpoint details about services hosted by a device. /// </returns> public DpwsMetadata Get(string serviceAddress) { // Convert the address string to a Uri Uri serviceUri = null; try { serviceUri = new Uri(serviceAddress); if (serviceUri.Scheme != "http") { System.Ext.Console.Write(""); System.Ext.Console.Write("Invalid serviceAddress. Must be a Uri. Http Uri schemes only."); System.Ext.Console.Write(""); return(null); } } catch (Exception e) { System.Ext.Console.Write(""); System.Ext.Console.Write(e.Message); System.Ext.Console.Write(""); return(null); } // Performance debugging DebugTiming timeDebuger = new DebugTiming(); long startTime = timeDebuger.ResetStartTime(""); // Build Get Request using (XmlMemoryWriter xmlWriter = XmlMemoryWriter.Create()) { WsWsaHeader header = new WsWsaHeader( WsWellKnownUri.WstNamespaceUri + "/Get", // Action null, // RelatesTo "urn:uuid:" + serviceUri.AbsolutePath.Substring(1), // To m_version.AnonymousUri, // ReplyTo null, null); // From, Any WsMessage msg = new WsMessage(header, null, WsPrefix.None, null, null); WsSoapMessageWriter smw = new WsSoapMessageWriter(m_version); String messageID = smw.WriteSoapMessageStart(xmlWriter, msg); // Performance debuging timeDebuger.PrintElapsedTime("*****Write Header Took"); // Performance debuging timeDebuger.PrintElapsedTime("*****Write Body Took"); smw.WriteSoapMessageEnd(xmlWriter); // Performance debuging timeDebuger.PrintTotalTime(startTime, "***Get Message Build Took"); // Create an Http client and send Get request WsHttpClient httpClient = new WsHttpClient(m_version); System.Ext.Console.Write(""); System.Ext.Console.Write("Sending Get to: " + serviceAddress); msg.Body = xmlWriter.ToArray(); WsMessage getResponse = httpClient.SendRequest(msg, new Uri(serviceAddress)); // If a get response is received process it and return DpwsMetadata object DpwsMetadata metadata = null; if (getResponse == null || getResponse.Body == null) { return(null); } else { DpwsDiscoClientProcessor soapProcessor = new DpwsDiscoClientProcessor(m_version); try { System.Ext.Console.Write(getResponse.Body as byte[]); System.Ext.Console.Write(""); metadata = soapProcessor.ProcessGetResponse((byte[])getResponse.Body, messageID); } catch (Exception e) { System.Ext.Console.Write(""); System.Ext.Console.Write("Get response parser threw an exception. " + e.Message); return(null); } } return(metadata); } }