public static MediaClient GetMediaBase(string url, string login, string pass) { try { if (!Network.Ping.IsOKServer(url)) { return(null); } 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(url + "/onvif/Media"); MediaClient mediaClient = new MediaClient(bind, mediaAddress); mediaClient.ClientCredentials.UserName.UserName = login; mediaClient.ClientCredentials.UserName.Password = pass; return(mediaClient); } catch { return(null); } }
private string GetMacAddress(Uri deviceUri) { var httpTransport = new HttpTransportBindingElement(); var httpTransportBinding = new HttpTransportBindingElement { AuthenticationScheme = AuthenticationSchemes.Digest }; var textMessageEncodingBinding = new TextMessageEncodingBindingElement { MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.None) }; var customBinding = new CustomBinding(textMessageEncodingBinding, httpTransportBinding); EndpointAddress serviceAddress = new EndpointAddress(deviceUri); var passwordDigestBehavior = new PasswordDigestBehavior("julian", "julian"); var deviceClient = new DeviceManagementService.DeviceClient(customBinding, serviceAddress); deviceClient.Endpoint.Behaviors.Add(passwordDigestBehavior); string model, firmwareVersion, serialNumber, hardwareId; deviceClient.GetDeviceInformation(out model, out firmwareVersion, out serialNumber, out hardwareId); return(serialNumber); }
public static string GetRecordingJobs(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.Digest; CustomBinding bind = new CustomBinding(messageElement, httpBinding); EndpointAddress mediaAddress = new EndpointAddress(set.GetONVIF + "/onvif/recording"); RecordingPortClient mediaClient = new RecordingPortClient(bind, mediaAddress); mediaClient.ClientCredentials.UserName.UserName = set.Login; mediaClient.ClientCredentials.UserName.Password = set.Password; var nodes = mediaClient.GetServiceCapabilities(); return(""); } catch { return("ERROR"); } }
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 bool PTZSupport(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/PTZ"); PTZClient mediaClient = new PTZClient(bind, mediaAddress); mediaClient.ClientCredentials.UserName.UserName = set.Login; mediaClient.ClientCredentials.UserName.Password = set.Password; var nodes = mediaClient.GetNodes(); return(nodes[0].HomeSupported); } catch { return(false); } }
public static string GetReplayUri(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/Replay"); ReplayPortClient mediaClient = new ReplayPortClient(bind, mediaAddress); mediaClient.ClientCredentials.UserName.UserName = set.Login; mediaClient.ClientCredentials.UserName.Password = set.Password; var ss = new OREP.StreamSetup { Stream = OREP.StreamType.RTPUnicast, Transport = new OREP.Transport() { Protocol = OREP.TransportProtocol.RTSP, } }; var nodes = mediaClient.GetReplayUri(ss, set.GetMediaTokens()[0]); return(nodes); } catch { return(""); } }
public static string PTZStatus(Structures set) { try { if (set.GetPTZTokens() == "" || !set.IsActive) { return(MoveStatus.UNKNOWN.ToString()); } 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/PTZ"); PTZClient mediaClient = new PTZClient(bind, mediaAddress); mediaClient.ClientCredentials.UserName.UserName = set.Login; mediaClient.ClientCredentials.UserName.Password = set.Password; try { var t = mediaClient.GetStatus(set.GetPTZTokens()).MoveStatus; return(t.PanTilt.ToString()); } catch { return(MoveStatus.UNKNOWN.ToString()); } } catch { return(MoveStatus.UNKNOWN.ToString()); } }
public void CreateVersionReturnsSameObjectReference() { Assert.AreSame( MessageVersion.CreateVersion(EnvelopeVersion.None, AddressingVersion.None), MessageVersion.CreateVersion(EnvelopeVersion.None, AddressingVersion.None) , "#1"); Assert.AreSame( MessageVersion.CreateVersion(EnvelopeVersion.Soap11, AddressingVersion.None), MessageVersion.CreateVersion(EnvelopeVersion.Soap11, AddressingVersion.None) , "#2"); Assert.AreSame( MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.WSAddressing10), MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.WSAddressing10) , "#3"); Assert.AreSame( MessageVersion.CreateVersion(EnvelopeVersion.Soap11, AddressingVersion.WSAddressing10), MessageVersion.CreateVersion(EnvelopeVersion.Soap11, AddressingVersion.WSAddressing10) , "#4"); Assert.AreSame( MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.None), MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.None) , "#5"); }
public static string GetSnapsotURL(Structures set, int profile = 1) { try { var tok = set.GetMediaTokens().FirstOrDefault(); if (tok == "" || !set.IsActive) { return(""); } 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/Media"); MediaClient mediaClient = new MediaClient(bind, mediaAddress); mediaClient.ClientCredentials.UserName.UserName = set.Login; mediaClient.ClientCredentials.UserName.Password = set.Password; MediaUri mediaUri = mediaClient.GetSnapshotUri(set.GetMediaTokens()[profile]); return(mediaUri.Uri); } catch { return(""); } }
public static void CountinuousRotatePTZ(Structures set, OPTZ.PTZSpeed speed, int timeout = -1) { try { if (set.GetPTZTokens() == "" || !set.IsActive) { return; } 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/PTZ"); PTZClient mediaClient = new PTZClient(bind, mediaAddress); mediaClient.ClientCredentials.UserName.UserName = set.Login; mediaClient.ClientCredentials.UserName.Password = set.Password; mediaClient.ContinuousMove(set.GetMediaTokens()[0], speed, "0"); System.Threading.Thread.Sleep(timeout <= 0 ? (int)Settings.StaticMembers.PTZSettings.Timeout : timeout);//1000 mediaClient.Stop(set.GetPTZTokens(), true, true); } catch { return; } }
public static void RotatePTZ(Structures set, PTZVector vector, OPTZ.PTZSpeed speed) { try { if (set.GetPTZTokens() == "" || !set.IsActive) { return; } 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/PTZ"); PTZClient mediaClient = new PTZClient(bind, mediaAddress); mediaClient.ClientCredentials.UserName.UserName = set.Login; mediaClient.ClientCredentials.UserName.Password = set.Password; var t = mediaClient.GetConfigurations()[0].DefaultPTZTimeout; mediaClient.RelativeMove(set.GetMediaTokens()[0], vector, speed); //set.GetMediaTokens()[0] //mediaClient.ContinuousMove(set.GetMediaTokens()[0], speed) } catch { return; } }
public static string GetStreamURL(Structures set, int profile = 0) { try { if (set.GetMediaTokens().FirstOrDefault() == "" || !set.IsActive) { return(""); } 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/Media"); MediaClient mediaClient = new MediaClient(bind, mediaAddress); mediaClient.ClientCredentials.UserName.UserName = set.Login; mediaClient.ClientCredentials.UserName.Password = set.Password; ServiceReference1.StreamSetup ss = new ServiceReference1.StreamSetup(); ss.Stream = ServiceReference1.StreamType.RTPUnicast; ss.Transport = new ServiceReference1.Transport(); ss.Transport.Protocol = ServiceReference1.TransportProtocol.RTSP; MediaUri mediaUri = mediaClient.GetStreamUri(ss, set.GetMediaTokens()[profile]); return(mediaUri.Uri); } catch { return(""); } }
CreateBindingElements() { BindingElement tx = new TransactionFlowBindingElement(TransactionProtocol.WSAtomicTransactionOctober2004); SecurityBindingElement sec = CreateMessageSecurity(); BindingElement msg = null; MessageVersion msgver = MessageVersion.CreateVersion(EnvelopeVersion, AddressingVersion.WSAddressing10); switch (MessageEncoding) { case WSMessageEncoding.Mtom: msg = new MtomMessageEncodingBindingElement(msgver, TextEncoding); break; case WSMessageEncoding.Text: msg = new TextMessageEncodingBindingElement(msgver, TextEncoding); break; default: throw new NotImplementedException("mhm, another WSMessageEncoding?"); } BindingElement tr = GetTransport(); List <BindingElement> list = new List <BindingElement> (); list.Add(tx); if (sec != null) { list.Add(sec); } list.Add(msg); if (tr != null) { list.Add(tr); } return(new BindingElementCollection(list.ToArray())); }
public async Task GetDeviceInfoAsync(string deviceAddress) { var messageElement = new TextMessageEncodingBindingElement { MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.None) }; HttpTransportBindingElement httpBinding = new HttpTransportBindingElement { AuthenticationScheme = AuthenticationSchemes.Digest }; CustomBinding bind = new CustomBinding(messageElement, httpBinding); //绑定服务地址 EndpointAddress serviceAddress = new EndpointAddress(deviceAddress); DeviceClient deviceClient = new DeviceClient(bind, serviceAddress); //查看系统时间 var date = await deviceClient.GetSystemDateAndTimeAsync(); Console.WriteLine(date.UTCDateTime.Date.Month.ToString()); //查看设备能力 GetCapabilitiesResponse cap = await deviceClient.GetCapabilitiesAsync(new CapabilityCategory[] { CapabilityCategory.All }); Console.WriteLine(cap.Capabilities.Media.XAddr.ToString()); }
public static void PTZStop(Structures set) { try { if (set.GetPTZTokens() == "" || !set.IsActive || !set.GetPTZController().IsSuported) { return; } 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/PTZ"); PTZClient mediaClient = new PTZClient(bind, mediaAddress); mediaClient.ClientCredentials.UserName.UserName = set.Login; mediaClient.ClientCredentials.UserName.Password = set.Password; mediaClient.Stop(set.GetPTZTokens(), true, true); } catch { return; } }
public DeviceViewModel() { EndpointAddress DeviceServiceRemoteAddress = new EndpointAddress("http://" + IpAddress + "/onvif/device_service"); HttpTransportBindingElement httpBinding = new HttpTransportBindingElement { AuthenticationScheme = AuthenticationSchemes.Digest }; var messageElement = new TextMessageEncodingBindingElement { MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.None) }; CustomBinding bind = new CustomBinding(messageElement, httpBinding); Client = new DeviceClient(bind, DeviceServiceRemoteAddress); PasswordDigestBehavior passwordDigestBehavior = new PasswordDigestBehavior(Username, Password); Client.Endpoint.Behaviors.Add(passwordDigestBehavior); Client.GetDeviceInformation(out string Model, out string FirmwareVersion, out string SerialNumber, out string HardwareId); Console.WriteLine("Model = " + Model); Console.WriteLine("FirmwareVersion = " + FirmwareVersion); Console.WriteLine("SerialNumber = " + SerialNumber); Console.WriteLine("HardwareId = " + HardwareId); }
public PTZClient(EndpointAddress epa, string username, string password) { EndPointAddress = epa; Username = username; Password = password; var httpBinding = new HttpTransportBindingElement { AuthenticationScheme = AuthenticationSchemes.Digest }; var messageElement = new TextMessageEncodingBindingElement { MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.None) }; var bind = new CustomBinding(messageElement, httpBinding); Client = new PTZ.PTZClient(bind, epa); if (!string.IsNullOrWhiteSpace(username) && !string.IsNullOrWhiteSpace(password)) { var behavior = new PasswordDigestBehavior(username, password); Client.Endpoint.EndpointBehaviors.Add(behavior); } // not initialized IsInitialized = false; }
private static Binding GetBindingForEndpoint(EndpointConfiguration endpointConfiguration) { if ((endpointConfiguration == EndpointConfiguration.SaleServiceSoap)) { BasicHttpBinding result = new BasicHttpBinding(); result.MaxBufferSize = int.MaxValue; result.ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max; result.MaxReceivedMessageSize = int.MaxValue; result.AllowCookies = true; result.Security.Mode = BasicHttpSecurityMode.Transport; return(result); } if ((endpointConfiguration == EndpointConfiguration.SaleServiceSoap12)) { CustomBinding result = new CustomBinding(); TextMessageEncodingBindingElement textBindingElement = new TextMessageEncodingBindingElement(); textBindingElement.MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.None); result.Elements.Add(textBindingElement); HttpsTransportBindingElement httpsBindingElement = new HttpsTransportBindingElement(); httpsBindingElement.AllowCookies = true; httpsBindingElement.MaxBufferSize = int.MaxValue; httpsBindingElement.MaxReceivedMessageSize = int.MaxValue; result.Elements.Add(httpsBindingElement); return(result); } throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration)); }
protected Binding CreateBinding() { CustomBinding result = new CustomBinding(); TextMessageEncodingBindingElement textBindingElement = new TextMessageEncodingBindingElement(); textBindingElement.MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap11, AddressingVersion.None); result.Elements.Add(textBindingElement); if (ReportSettings.IsSSL) { HttpsTransportBindingElement httpBindingElement = new HttpsTransportBindingElement(); httpBindingElement.AllowCookies = true; httpBindingElement.MaxBufferSize = int.MaxValue; httpBindingElement.MaxReceivedMessageSize = int.MaxValue; httpBindingElement.AuthenticationScheme = AuthenticationSchemes.Ntlm; result.Elements.Add(httpBindingElement); } else { HttpTransportBindingElement httpBindingElement = new HttpTransportBindingElement(); httpBindingElement.AllowCookies = true; httpBindingElement.MaxBufferSize = int.MaxValue; httpBindingElement.MaxReceivedMessageSize = int.MaxValue; httpBindingElement.AuthenticationScheme = AuthenticationSchemes.Ntlm; result.Elements.Add(httpBindingElement); } return(result); }
private static MessageVersion ConvertMessageVersion(System.ServiceModel.Channels.MessageVersion version) { EnvelopeVersion envelopeVersion = null; if (System.ServiceModel.EnvelopeVersion.None.Equals(version.Envelope)) { envelopeVersion = EnvelopeVersion.None; } else if (System.ServiceModel.EnvelopeVersion.Soap11.Equals(version.Envelope)) { envelopeVersion = EnvelopeVersion.Soap11; } else if (System.ServiceModel.EnvelopeVersion.Soap12.Equals(version.Envelope)) { envelopeVersion = EnvelopeVersion.Soap12; } AddressingVersion addressingVersion = null; if (System.ServiceModel.Channels.AddressingVersion.None.Equals(version.Addressing)) { addressingVersion = AddressingVersion.None; } else if (System.ServiceModel.Channels.AddressingVersion.WSAddressing10.Equals(version.Addressing)) { addressingVersion = AddressingVersion.WSAddressing10; } else if (System.ServiceModel.Channels.AddressingVersion.WSAddressingAugust2004.Equals(version.Addressing)) { addressingVersion = AddressingVersion.WSAddressingAugust2004; } return(MessageVersion.CreateVersion(envelopeVersion, addressingVersion)); }
public void init() { string authorizationServerEndpoint = ConfigurationManager.AppSettings["authorizationServerEndpoint"]; clientId = ConfigurationManager.AppSettings["clientId"]; clientSecret = ConfigurationManager.AppSettings["clientSecret"]; string endpointTransportGuarantee = ConfigurationManager.AppSettings["endpointTransportGuarantee"]; bool disableCertificateValidation = Convert.ToBoolean(ConfigurationManager.AppSettings["disableCertificateValidation"]); var messageElement = new TextMessageEncodingBindingElement(); TransportBindingElement transportElement; if ("NONE".Equals(endpointTransportGuarantee)) { transportElement = new HttpTransportBindingElement(); } else if ("CONFIDENTIAL".Equals(endpointTransportGuarantee)) { transportElement = new HttpsTransportBindingElement(); } else { throw new OAuth2ClientException("Invalid endpointTransportGuarantee value: " + endpointTransportGuarantee); } messageElement.MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap11, AddressingVersion.None); CustomBinding binding = new CustomBinding(messageElement, transportElement); EndpointAddress endpoint = new EndpointAddress(new Uri(authorizationServerEndpoint)); client = new OAuth2Protocol.AccessTokenRequestor.OAuthPortTypeClient(binding, endpoint); if (disableCertificateValidation) { System.Net.ServicePointManager.ServerCertificateValidationCallback = ((sender, certificate, chain, sslPolicyErrors) => true); } }
private void onvifVideo(string url, string user, string password) { try { AddInfo("Efetuando login em " + url); // http://stackoverflow.com/questions/31007828/onvif-getstreamurl-c-sharp // Adicionar a referencia de serviço: http://www.onvif.org/onvif/ver10/media/wsdl/media.wsdl // http://stackoverflow.com/questions/32779467/onvif-api-capture-image-in-c-sharp 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(url + "/onvif/Media"); MediaClient mediaClient = new MediaClient(bind, mediaAddress); mediaClient.ClientCredentials.UserName.UserName = user; mediaClient.ClientCredentials.UserName.Password = password; Profile[] profiles = mediaClient.GetProfiles(); StreamSetup streamSetup = new StreamSetup(); streamSetup.Stream = StreamType.RTPUnicast; streamSetup.Transport = new Transport(); streamSetup.Transport.Protocol = TransportProtocol.RTSP; var uri = mediaClient.GetStreamUri(streamSetup, profiles[1].token); AddInfo(uri.Uri); } catch (Exception ex) { AddInfo(ex); } }
public static PullPointSubscriptionClient GetPullPointSubClient(string ip, int port, string toHeaderAddr, List <MessageHeader> headers) { //EndpointAddress serviceAddress = new EndpointAddress(string.Format("http://{0}:{1}/onvif/event_service", ip, port)); AddressHeader[] addrHeader; // = AddressHeader.CreateAddressHeader("Action", "http://www.w3.org/2005/08/addressing", "http://docs.oasis-open.org/wsn/bw-2/NotificationProducer/SubscribeRequest"); addrHeader = new AddressHeader[2]; addrHeader[0] = AddressHeader.CreateAddressHeader("Action", "http://www.w3.org/2005/08/addressing", "http://www.onvif.org/ver10/events/wsdl/PullPointSubscription/PullMessagesRequest"); addrHeader[1] = AddressHeader.CreateAddressHeader("To", "http://www.w3.org/2005/08/addressing", toHeaderAddr); //addrHeader[1] = AddressHeader.CreateAddressHeader("MessageID", "http://www.w3.org/2005/08/addressing", "urn:uuid:e47b9746-c5c1-455e-839f-0db5bed7d8c7"); //addrHeader[1] = AddressHeader.CreateAddressHeader("ReplyTo", "http://www.w3.org/2005/08/addressing", "http://www.w3.org/2005/08/addressing/anonymous"); //MessageHeader[] msgHeader; //msgHeader = new MessageHeader[1]; //msgHeader[0] = MessageHeader.CreateHeader("Action", "http://www.w3.org/2005/08/addressing", "http://docs.oasis-open.org/wsn/bw-2/NotificationProducer/SubscribeRequest", true); EndpointAddress serviceAddress = new EndpointAddress( new System.Uri(string.Format("http://{0}:{1}/onvif/event_service", ip, port)), addrHeader); HttpTransportBindingElement httpBinding = new HttpTransportBindingElement(); httpBinding.AuthenticationScheme = AuthenticationSchemes.Digest; var messageElement = new TextMessageEncodingBindingElement(); messageElement.MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.None); CustomBinding bind = new CustomBinding(messageElement, httpBinding); PullPointSubscriptionClient ppsc = new PullPointSubscriptionClient(bind, serviceAddress); return(ppsc); }
public async Task <string> CallESBClient(ProcessInterfaceDataChangeLogsRequest request, string paymentRequestMessage, string legalEntityCode) { HttpsTransportBindingElement httpsTransport = new HttpsTransportBindingElement(); httpsTransport.AuthenticationScheme = System.Net.AuthenticationSchemes.Basic; CustomBinding esbCustomBinding = new CustomBinding(); TextMessageEncodingBindingElement esbTextMessageEncod = new TextMessageEncodingBindingElement(); esbTextMessageEncod.MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.None); esbTextMessageEncod.WriteEncoding = Encoding.UTF8; esbCustomBinding.Elements.Add(esbTextMessageEncod); esbCustomBinding.Elements.Add(httpsTransport); var uri = string.Format(CultureInfo.InvariantCulture, "{0}/ws/LDC.API.processPaymentOrder_v1.soap:ws/LDC_API_processPaymentOrder_v1_soap_ws_Port", _settings.EnvironmentLink); EndpointAddress esbRemoteAddress = new EndpointAddress(uri); ESBPaymentRequestClient.ws_PortTypeClient esbClient = new ESBPaymentRequestClient.ws_PortTypeClient(esbCustomBinding, esbRemoteAddress); esbClient.ClientCredentials.UserName.UserName = _settings.UserName; esbClient.ClientCredentials.UserName.Password = _settings.Password; string fileName = string.Format(CultureInfo.InvariantCulture, "{0}_{1}_{2}.{3}", _settings.FileNameCompany, legalEntityCode, DateTime.UtcNow.ToString("yyyyMMddHHmmss", CultureInfo.InvariantCulture), _settings.FileNameFormat); _logger.LogInformation("Calling ESB at {Atlas_EsbUri} with {Atlas_EsbFileName} {Atlas_EsbMessage}", uri, fileName, paymentRequestMessage); ESBPaymentRequestClient.processResponse esbResponse = await esbClient.processAsync(fileName, legalEntityCode, Encoding.UTF8.GetBytes(paymentRequestMessage)); return(esbResponse.uuid); }
public async Task <Tuple <string, GetDeviceInformationResponse> > GetDeviceInfoAsync(string deviceAddress, string userName, string password) { var messageElement = new TextMessageEncodingBindingElement { MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.None) }; HttpTransportBindingElement httpBinding = new HttpTransportBindingElement { //AuthenticationScheme = AuthenticationSchemes.Digest }; CustomBinding bind = new CustomBinding(messageElement, httpBinding); //绑定服务地址 EndpointAddress serviceAddress = new EndpointAddress(deviceAddress); DeviceClient deviceClient = new DeviceClient(bind, serviceAddress); //给每个请求都添加认证信息 deviceClient.Endpoint.EndpointBehaviors.Add(new CustomEndpointBehavior(userName, password)); //查看系统时间 var date = await deviceClient.GetSystemDateAndTimeAsync(); Console.WriteLine(date.UTCDateTime.Date.Month.ToString()); var deviceInfo = await deviceClient.GetDeviceInformationAsync(new GetDeviceInformationRequest() { }); //查看设备能力 GetCapabilitiesResponse cap = await deviceClient.GetCapabilitiesAsync(new CapabilityCategory[] { CapabilityCategory.All }); return(Tuple.Create <string, GetDeviceInformationResponse>(cap.Capabilities.Media.XAddr.ToString(), deviceInfo)); }
static void Main(string [] args) { try { /* Discovery doesn't work in Mono * var endPoint = new UdpDiscoveryEndpoint (DiscoveryVersion.WSDiscoveryApril2005); * * var discoveryClient = new DiscoveryClient (endPoint); * * discoveryClient.FindProgressChanged += discoveryClient_FindProgressChanged; * discoveryClient.FindCompleted += (sender, e) => { * Console.WriteLine ("Discovery finished"); * }; * FindCriteria findCriteria = new FindCriteria (); * //findCriteria.Duration = TimeSpan.MaxValue; * findCriteria.Duration = TimeSpan.FromSeconds (10); * findCriteria.MaxResults = int.MaxValue; * discoveryClient.FindAsync (findCriteria); * * //Console.ReadKey (); */ HttpTransportBindingElement httpBinding = new HttpTransportBindingElement(); httpBinding.AuthenticationScheme = AuthenticationSchemes.Digest; var messageElement = new TextMessageEncodingBindingElement(); // FIXME: Probe for Soap12 if Soap11 fails messageElement.MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.None); CustomBinding binding = new CustomBinding(messageElement, httpBinding); EndpointAddress address = new EndpointAddress(@"http://192.168.1.130:8080/onvif/device_service"); OnvifServices.OnvifDeviceService.DeviceClient device = new OnvifServices.OnvifDeviceService.DeviceClient(binding, address); device.ClientCredentials.UserName.UserName = @"admin"; device.ClientCredentials.UserName.Password = @"admin"; var dateTime = device.GetSystemDateAndTime(); var services = device.GetServices(true); foreach (var service in services) { if (service.Namespace == "http://www.onvif.org/ver10/media/wsdl") { OnvifServices.OnvifMediaService.MediaClient client = new OnvifServices.OnvifMediaService.MediaClient(binding, address); client.ClientCredentials.UserName.UserName = @"admin"; client.ClientCredentials.UserName.Password = @"admin"; var profiles = client.GetProfiles(); // use the first profile (the device has at least one media profile). var targetProfileToken = profiles [0].token; // set the GetStreamUriRequest paramater var streamSetup = new OnvifServices.OnvifMediaService.StreamSetup(); streamSetup.Stream = OnvifServices.OnvifMediaService.StreamType.RTPUnicast; streamSetup.Transport = new OnvifServices.OnvifMediaService.Transport(); streamSetup.Transport.Protocol = OnvifServices.OnvifMediaService.TransportProtocol.RTSP; streamSetup.Transport.Tunnel = null; var mediaUri = client.GetStreamUri(streamSetup, targetProfileToken); } } } catch (Exception ex) { Console.Out.WriteLine($"Error: {ex.Message} \r\n{ex.StackTrace}"); } }
public IOnvifClienBuilder <DeviceClient> SetMessageElement() { _messageElement = new TextMessageEncodingBindingElement() { MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.None) }; return(this); }
public void CreateFaultWithNumberCode() { var msgVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap11, AddressingVersion.None); var msg = Message.CreateMessage(XmlReader.Create(new StreamReader(TestResourceHelper.GetFullPathOfResource("Test/Resources/soap-fault-number.xml"))), 0x10000, msgVersion); MessageFault.CreateFault(msg, 0x10000); }
/// <summary> /// Inicializa uma nova instancia da classe <see cref="DFeSoap12ServiceClientBase{T}"/>. /// </summary> /// <param name="url">The URL.</param> /// <param name="timeOut">The time out.</param> /// <param name="certificado">The certificado.</param> protected DFeSoap12ServiceClientBase(string url, TimeSpan?timeOut = null, X509Certificate2 certificado = null) : base(url, timeOut, certificado) { var custom = new CustomBinding(Endpoint.Binding); var version = custom.Elements.Find <TextMessageEncodingBindingElement>(); version.MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.None); Endpoint.Binding = custom; }
protected NFSeSOAP12ServiceClient(ProviderBase provider, TipoUrl tipoUrl) : base(provider, tipoUrl) { var custom = new CustomBinding(Endpoint.Binding); var version = custom.Elements.Find <TextMessageEncodingBindingElement>(); version.MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.None); Endpoint.Binding = custom; }