public static NotificationMessageHolderType[] GetEvents(Structures set) { try { //if (set.GetPTZTokens() == "" || !set.IsActive) return false; var messageElement = new TextMessageEncodingBindingElement(); messageElement.MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.None); HttpTransportBindingElement httpBinding = new HttpTransportBindingElement(); httpBinding.AuthenticationScheme = AuthenticationSchemes.Basic; CustomBinding bind = new CustomBinding(messageElement, httpBinding); EndpointAddress mediaAddress = new EndpointAddress(set.GetONVIF + "/onvif/event"); PullPointSubscriptionClient mediaClient = new PullPointSubscriptionClient(bind, mediaAddress); mediaClient.ClientCredentials.UserName.UserName = set.Login; mediaClient.ClientCredentials.UserName.Password = set.Password; NotificationMessageHolderType[] t; DateTime term; var nodes = mediaClient.PullMessages("1", 1, null, out term, out t); return(t); } catch { return(new NotificationMessageHolderType[] { }); } }
public static void ManejaEventos(string uri) { try { ServicePointManager.Expect100Continue = false; EndpointAddress endPointAddress = new EndpointAddress(uri); HttpTransportBindingElement httpTransportBinding = new HttpTransportBindingElement { AuthenticationScheme = AuthenticationSchemes.Digest }; httpTransportBinding.KeepAliveEnabled = true; TextMessageEncodingBindingElement textMessageEncodingBinding = new TextMessageEncodingBindingElement { MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.WSAddressing10) }; PasswordDigestBehavior passwordDigestBehavior = new PasswordDigestBehavior("julian", "julian"); CustomBinding customBinding = new CustomBinding(textMessageEncodingBinding, httpTransportBinding); customBinding.SendTimeout = new TimeSpan(0, 0, 10); EventPortTypeClient ept = new EventPortTypeClient(customBinding, endPointAddress); ept.Endpoint.Behaviors.Add(passwordDigestBehavior); Console.WriteLine("Status 1 : " + ept.State.ToString()); ept.Open(); Console.WriteLine("Status 2 : " + ept.State.ToString()); ept.GetType(); ept.GetHashCode(); FilterType filter = new FilterType(); string initTermTime = null; CreatePullPointSubscriptionSubscriptionPolicy policy = new CreatePullPointSubscriptionSubscriptionPolicy(); XmlElement[] elems1 = new XmlElement[10]; System.DateTime time1 = new System.DateTime(); Nullable <System.DateTime> time2 = new System.DateTime(); EndpointReferenceType endpoint = ept.CreatePullPointSubscription(filter, "PT60M", policy, ref elems1, out time1, out time2); System.DateTime CurrentTime = new System.DateTime(); NotificationMessageHolderType[] NotificationMessages = new NotificationMessageHolderType[0]; PullPointSubscriptionClient.PullMessages() PullPointSubscriptionClient.PullMessages("PT5M", 99, Any, out CurrentTime, out NotificationMessages); PullPointSubscriptionClient subbind = new PullPointSubscriptionClient(customBinding, endPointAddress); subbind.Endpoint.Behaviors.Add(passwordDigestBehavior); string timeOut = "PT60.000S"; int mesLimit = 100; XmlElement[] elemns2 = new XmlElement[10]; System.DateTime termTime = new System.DateTime(); NotificationMessageHolderType[] messHolder = new NotificationMessageHolderType[0]; subbind.PullMessages(timeOut, mesLimit, elemns2, out termTime, out messHolder); for (int i = 0; i < messHolder.Length; i++) { Console.WriteLine("parsing"); } Console.WriteLine("--------- NO CATCH --------- "); } catch (Exception eee) { Console.WriteLine("manejando eventos: " + eee); } }