• 大小: 263KB
    文件类型: .rar
    金币: 2
    下载: 2 次
    发布日期: 2021-06-10
  • 语言: C#
  • 标签: onvif  C#  

资源简介

本demo,基于vs2017开发,采用C#开发语言,实现了onvif协议之抓图功能

资源截图

代码片段和文件信息

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个文件信息

评论

共有 条评论