public static NotificationConsumerClient GetNotificationConsumerClient(string ip, int port, string subscription) { EndpointAddress serviceAddress = new EndpointAddress(string.Format("http://{0}:{1}/{2}", ip, port, subscription)); HttpTransportBindingElement httpBinding = new HttpTransportBindingElement(); httpBinding.AuthenticationScheme = AuthenticationSchemes.Digest; var messageElement = new TextMessageEncodingBindingElement(); messageElement.MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.WSAddressing10); CustomBinding bind = new CustomBinding(messageElement, httpBinding); NotificationConsumerClient client = new NotificationConsumerClient(bind, serviceAddress); return(client); }
public override async Task <bool> InitalizeAsync() { if (this.m_onVifDevice.ServicesResponse == null) { bool b = await this.m_onVifDevice.InitalizeDeviceAsync(); if (this.m_onVifDevice.ServicesResponse == null) { return(false); } } try { foreach (var service in this.m_onVifDevice.ServicesResponse.Service) { if (service.Namespace == "http://www.onvif.org/ver10/events/wsdl") { string serviceAdress = service.XAddr; HttpTransportBindingElement httpBinding = new HttpTransportBindingElement(); httpBinding.AuthenticationScheme = AuthenticationSchemes.Digest; var messageElement = new TextMessageEncodingBindingElement(); messageElement.MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.WSAddressing10); CustomBinding binding = new CustomBinding(messageElement, httpBinding); /* * this.m_EventPortTypeClient = new EventPortTypeClient(binding, new EndpointAddress($"http://{ this.m_onVifDevice.Hostname}/onvif/event_service")); * this.m_EventPortTypeClient.Endpoint.EndpointBehaviors.Add(this.m_onVifDevice.GetPasswordDigestBehavior); * CreatePullPointSubscriptionRequest request = new CreatePullPointSubscriptionRequest(); * request.InitialTerminationTime = "PT60S"; * request.SubscriptionPolicy = new CreatePullPointSubscriptionSubscriptionPolicy(); * * * m_PullPointResponse = await this.m_EventPortTypeClient.CreatePullPointSubscriptionAsync(request); * * * * * PullMessagesRequest message = new PullMessagesRequest("PT1S", 1024, null); * * await m_PullPointSubscriptionClient.PullMessagesAsync(message); * * GetEventPropertiesRequest eventrequest = new GetEventPropertiesRequest(); * m_EventPropertiesResponse =await this.m_EventPortTypeClient.GetEventPropertiesAsync(eventrequest); */ OnvifDevice.Capabilities response = await this.m_onVifDevice.GetDeviceCapabilitiesAsync(); NotificationConsumerClient consclient = new NotificationConsumerClient(binding, new EndpointAddress(serviceAdress)); consclient.Endpoint.EndpointBehaviors.Add(this.m_onVifDevice.GetPasswordDigestBehavior); consclient.Endpoint.EndpointBehaviors.Add(this.m_onVifDevice.GetBasicBasicAuthBehaviour); OnvifEvent10.Notify request = new OnvifEvent10.Notify(); // await consclient.NotifyAsync(request); // await consclient.OpenAsync(); NotificationConsumerService _notificationConsumerService = new NotificationConsumerService(); // _notificationConsumerService.NewNotification += _notificationConsumerService_NewNotification; // ServiceHost _notificationConsumerServiceHost = new ServiceHost(_notificationConsumerService, new Uri("http://localhost:8085/NotificationConsumerService")); // _notificationConsumerServiceHost.Open(); NotificationProducerClient client = new NotificationProducerClient(binding, new EndpointAddress(serviceAdress)); client.Endpoint.EndpointBehaviors.Add(this.m_onVifDevice.GetPasswordDigestBehavior); client.Endpoint.EndpointBehaviors.Add(this.m_onVifDevice.GetBasicBasicAuthBehaviour); var subScribe = new Subscribe() { ConsumerReference = new EndpointReferenceType { Address = new AttributedURIType { Value = consclient.Endpoint.Address.Uri.ToString() }, } }; subScribe.InitialTerminationTime = "PT2H"; SubscribeResponse1 resp = await client.SubscribeAsync(subScribe); if ((response.Events != null) && response.Events.WSSubscriptionPolicySupport) { m_PullPointSubscriptionClient = new PullPointSubscriptionClient(binding, new EndpointAddress(serviceAdress)); m_SubscriptionManagerClient = new SubscriptionManagerClient(binding, new EndpointAddress(serviceAdress)); m_PullPointSubscriptionClient.Endpoint.EndpointBehaviors.Add(this.m_onVifDevice.GetPasswordDigestBehavior); m_PullPointSubscriptionClient.Endpoint.EndpointBehaviors.Add(this.m_onVifDevice.GetBasicBasicAuthBehaviour); m_SubscriptionManagerClient.Endpoint.EndpointBehaviors.Add(this.m_onVifDevice.GetPasswordDigestBehavior); m_SubscriptionManagerClient.Endpoint.EndpointBehaviors.Add(this.m_onVifDevice.GetBasicBasicAuthBehaviour); return(true); } else { // throw new DeviceEventReceiverException("Device doesn't support pull point subscription"); } if ((response.Events != null) && response.Events.WSPullPointSupport) { m_PullPointSubscriptionClient = new PullPointSubscriptionClient(binding, new EndpointAddress(serviceAdress)); m_SubscriptionManagerClient = new SubscriptionManagerClient(binding, new EndpointAddress(serviceAdress)); m_PullPointSubscriptionClient.Endpoint.EndpointBehaviors.Add(this.m_onVifDevice.GetPasswordDigestBehavior); m_PullPointSubscriptionClient.Endpoint.EndpointBehaviors.Add(this.m_onVifDevice.GetBasicBasicAuthBehaviour); m_SubscriptionManagerClient.Endpoint.EndpointBehaviors.Add(this.m_onVifDevice.GetPasswordDigestBehavior); m_SubscriptionManagerClient.Endpoint.EndpointBehaviors.Add(this.m_onVifDevice.GetBasicBasicAuthBehaviour); return(true); } else { throw new DeviceEventReceiverException("Device doesn't support pull point subscription"); } } } } catch (Exception ex) { m_ErrorMessage = ex.Message; return(false); } return(m_initialised); }