資源簡介
本demo,基于vs2017開發(fā),采用C#開發(fā)語言,實現(xiàn)了onvif協(xié)議之抓圖功能

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.IO;
using?System.Linq;
using?System.Net;
using?System.ServiceModel;
using?System.ServiceModel.Channels;
using?System.ServiceModel.Discovery;
using?System.Text;
using?System.Threading.Tasks;
using?TestOnvifClient.devicemgmt;
using?TestOnvifClient.Media;
using?static?System.Net.Mime.MediaTypeNames;
namespace?TestOnvifClient
{
????class?Program
????{
????????static?void?Main(string[]?args)
????????{
????????????Test();
????????????Console.Read();
????????}
????????static?void?Test()
????????{
????????????string?username?=?“admin“;
????????????string?password?=?“Admin123“;
????????????string?ip?=?“10.10.14.172“;
????????????int?port?=?80;
????????????EndpointAddress?serviceAddress?=?new?EndpointAddress(string.Format(“http://{0}:{1}/onvif/Media“?ip?port));
????????????HttpTransportBindingElement?httpBinding?=?new?HttpTransportBindingElement();
????????????httpBinding.AuthenticationScheme?=?AuthenticationSchemes.Digest;
????????????httpBinding.KeepAliveEnabled?=?false;
????????????var?messageElement?=?new?TextMessageEncodingBindingElement();
????????????messageElement.MessageVersion?=?MessageVersion.CreateVersion(EnvelopeVersion.Soap12?AddressingVersion.None);
????????????CustomBinding?bind?=?new?CustomBinding(messageElement?httpBinding);
????????????//DeviceClient?deviceClient?=?new?DeviceClient(bind?serviceAddress);
????????????MediaClient?mediaClient?=?new?MediaClient(bind?serviceAddress);
????????????if?(username?!=?string.Empty)
????????????{
????????????????//?Handles?adding?of?SOAP?Security?header?containing?User?Token?(user?nonce?pwd?digest)
????????????????PasswordDigestBehavior?behavior?=?new?PasswordDigestBehavior(username?password);
????????????????mediaClient.Endpoint.Behaviors.Add(behavior);
????????????}
????????????Profile[]?mProfiles?=?mediaClient.GetProfiles();
????????????if?(mProfiles.Length?>?0)
????????????{
????????????????var?ttt?=?mediaClient.GetSnapshotUri(mProfiles[0].token);
????????????????if(SavePhotoFromUrl(“pictest.JPEG“?ttt.Uri))
????????????????{
????????????????????Console.WriteLine(“success“);
????????????????}
????????????}
???????????
????????????Console.WriteLine(“11111“);
????????}
????????public?static?bool?SavePhotoFromUrl(string?FileName?string?Url)
????????{
????????????bool?Value?=?false;
????????????WebResponse?response?=?null;
????????????Stream?stream?=?null;
????????????try
????????????{
????????????????HttpWebRequest?request?=?(HttpWebRequest)WebRequest.Create(Url);
????????????????request.Credentials?=?new?NetworkCredential(“admin“?“Admin123“);
????????????????//request.
????????????????response?=?request.GetResponse();
????????????????stream?=?response.GetResponseStream();
????????????????if?(!response.ContentType.ToLower().StartsWith(“text/“))
????????????????{
????????????????????Value?=?SaveBinaryFile(response?FileName);
????????????????}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????709??2018-04-25?09:05??TestOnvifClient\App.config
?????文件??????18201??2018-04-23?11:35??TestOnvifClient\Connected?Services\devicemgmt\b-2.xsd
?????文件???????2467??2018-04-23?11:35??TestOnvifClient\Connected?Services\devicemgmt\bf-2.xsd
?????文件???????6457??2018-04-23?11:35??TestOnvifClient\Connected?Services\devicemgmt\common.xsd
?????文件????????743??2018-04-23?11:35??TestOnvifClient\Connected?Services\devicemgmt\configuration.svcinfo
?????文件??????15690??2018-04-23?11:35??TestOnvifClient\Connected?Services\devicemgmt\configuration91.svcinfo
?????文件?????186573??2018-04-23?11:35??TestOnvifClient\Connected?Services\devicemgmt\devicemgmt.wsdl
?????文件????????547??2018-04-23?11:35??TestOnvifClient\Connected?Services\devicemgmt\include.xsd
?????文件???????4405??2018-04-23?11:35??TestOnvifClient\Connected?Services\devicemgmt\item.xsd
?????文件?????377663??2018-04-23?11:35??TestOnvifClient\Connected?Services\devicemgmt\onvif.xsd
?????文件?????826058??2018-04-23?11:35??TestOnvifClient\Connected?Services\devicemgmt\Reference.cs
?????文件???????3417??2018-04-23?11:35??TestOnvifClient\Connected?Services\devicemgmt\Reference.svcmap
?????文件???????5705??2018-04-23?11:35??TestOnvifClient\Connected?Services\devicemgmt\t-1.xsd
?????文件????????657??2018-04-23?11:35??TestOnvifClient\Connected?Services\devicemgmt\TestOnvifClient.devicemgmt.AddScopesResponse.datasource
?????文件????????643??2018-04-23?11:35??TestOnvifClient\Connected?Services\devicemgmt\TestOnvifClient.devicemgmt.BackupFile.datasource
?????文件????????643??2018-04-23?11:35??TestOnvifClient\Connected?Services\devicemgmt\TestOnvifClient.devicemgmt.BinaryData.datasource
?????文件????????647??2018-04-23?11:35??TestOnvifClient\Connected?Services\devicemgmt\TestOnvifClient.devicemgmt.Capabilities.datasource
?????文件????????645??2018-04-23?11:35??TestOnvifClient\Connected?Services\devicemgmt\TestOnvifClient.devicemgmt.Certificate.datasource
?????文件????????667??2018-04-23?11:35??TestOnvifClient\Connected?Services\devicemgmt\TestOnvifClient.devicemgmt.CertificateInformation.datasource
?????文件????????657??2018-04-23?11:35??TestOnvifClient\Connected?Services\devicemgmt\TestOnvifClient.devicemgmt.CertificateStatus.datasource
?????文件????????673??2018-04-23?11:35??TestOnvifClient\Connected?Services\devicemgmt\TestOnvifClient.devicemgmt.CreateCertificateResponse.datasource
?????文件????????661??2018-04-23?11:35??TestOnvifClient\Connected?Services\devicemgmt\TestOnvifClient.devicemgmt.CreateUsersResponse.datasource
?????文件????????675??2018-04-23?11:35??TestOnvifClient\Connected?Services\devicemgmt\TestOnvifClient.devicemgmt.DeleteCertificatesResponse.datasource
?????文件????????687??2018-04-23?11:35??TestOnvifClient\Connected?Services\devicemgmt\TestOnvifClient.devicemgmt.DeleteDot1XConfigurationResponse.datasource
?????文件????????673??2018-04-23?11:35??TestOnvifClient\Connected?Services\devicemgmt\TestOnvifClient.devicemgmt.DeleteGeoLocationResponse.datasource
?????文件????????661??2018-04-23?11:35??TestOnvifClient\Connected?Services\devicemgmt\TestOnvifClient.devicemgmt.DeleteUsersResponse.datasource
?????文件????????673??2018-04-23?11:35??TestOnvifClient\Connected?Services\devicemgmt\TestOnvifClient.devicemgmt.DeviceServiceCapabilities.datasource
?????文件????????649??2018-04-23?11:35??TestOnvifClient\Connected?Services\devicemgmt\TestOnvifClient.devicemgmt.DiscoveryMode.datasource
?????文件????????651??2018-04-23?11:35??TestOnvifClient\Connected?Services\devicemgmt\TestOnvifClient.devicemgmt.DNSInformation.datasource
?????文件????????667??2018-04-23?11:35??TestOnvifClient\Connected?Services\devicemgmt\TestOnvifClient.devicemgmt.Dot11AvailableNetworks.datasource
............此處省略151個文件信息
評論
共有 條評論