public static string GetSoapPacket(string response) { string rawSoapPacket = null; System.IO.StringReader rdr = new StringReader(response); string nextLine; do { nextLine = rdr.ReadLine(); } while (!string.IsNullOrEmpty(nextLine)); rawSoapPacket = rdr.ReadToEnd(); // fix for #976 rawSoapPacket = BaseNotificationXmlUtils.RemoveInvalidXmlChars(rawSoapPacket); return(rawSoapPacket); }
protected List <FindEventResult> GetAllEventsSearchResults(string searchToken, int?minResults, int?maxResults, string waitTime, Dictionary <FindEventResult, XmlElement> rawResults, out SearchState state) { List <FindEventResult> eventsList = new List <FindEventResult>(); FindEventResultList response = null; GetEventSearchResults request = new GetEventSearchResults(); request.SearchToken = searchToken; request.WaitTime = waitTime; request.MaxResultsSpecified = maxResults.HasValue; request.MaxResults = maxResults.GetValueOrDefault(); request.MinResultsSpecified = minResults.HasValue; request.MinResults = minResults.GetValueOrDefault(); string dump = string.Empty; Action <string> logAction = new Action <string>(str => { dump = str; }); _trafficListener.ResponseReceived += logAction; DateTime started = DateTime.Now; DateTime dueTo = started.AddSeconds(_searchTimeout); bool completed = true; DateTime lastResponse = DateTime.Now; LogTestEvent(string.Format("All results should be received by {0}{1}", dueTo.StdTimeToString(), Environment.NewLine)); do { RunStep(() => { response = Client.GetEventSearchResults(request).ResultList; }, "Get Events Search results"); lastResponse = DateTime.Now; var events = response.Result ?? new FindEventResult[0]; // no request delay here! var onvifEvents = events.Where(OnvifMessage.IsOnvifMessage); if (events.Count() != onvifEvents.Count()) { LogStepEvent("WARNING: there is a message from non-ONVIF namespace"); } //if (null != rawResults) { var rdr = new System.IO.StringReader(dump); string nextLine; do { nextLine = rdr.ReadLine(); } while (!string.IsNullOrEmpty(nextLine)); string rawSoapPacket = rdr.ReadToEnd(); // fix for #976 rawSoapPacket = BaseNotificationXmlUtils.RemoveInvalidXmlChars(rawSoapPacket); var doc = new XmlDocument(); doc.LoadXml(rawSoapPacket); var messagePath = "/s:Envelope/s:Body/search:GetEventSearchResultsResponse/search:ResultList/onvif:Result/onvif:Event"; var manager = new XmlNamespaceManager(doc.NameTable); manager.AddNamespace("s", "http://www.w3.org/2003/05/soap-envelope"); manager.AddNamespace("search", "http://www.onvif.org/ver10/search/wsdl"); manager.AddNamespace("onvif", "http://www.onvif.org/ver10/schema"); manager.AddNamespace("b2", "http://docs.oasis-open.org/wsn/b-2"); XmlNodeList responseNodeList = doc.SelectNodes(messagePath, manager); for (int i = 0; i < events.Count(); i++) { var e = events[i]; if (OnvifMessage.IsOnvifMessage(e)) { eventsList.Add(e); if (null != rawResults) { rawResults.Add(e, responseNodeList[i] as XmlElement); } } } } if (lastResponse > dueTo) { completed = false; break; } } while (response.SearchState != SearchState.Completed); state = response.SearchState; _trafficListener.ResponseReceived -= logAction; Assert(completed, string.Format("Completed state has not been achieved (last response received at {0}, State: {1})", lastResponse.StdTimeToString(), response.SearchState), "Check that search has been completed in due time"); return(eventsList); }