找不到媒体和设备对象或名称空间

问题描述

我对C#还是很陌生,并且正在尝试编写一个基本程序来通过Onvif摄像头设备传输视频。我几乎能够了解并了解this 8 min tutorial

但是有些事情我不知道。即使在添加了Vlc引用和两个Onvif服务引用之后,仍有一些代码无法编译。该教程很难遵循,因为他跳过了主要步骤。我正在尝试确定以下代码中的DeviceMediaEndPointAddress代表什么(根据他的教程)。

public partial class MainWindow : Window
{
   UriBuilder deviceUri;
   Media.Media2Client media;
   Media.MediaProfile[] profiles;

   public MainWindow()
   {
      InitializeComponent();
   }


   private void button1_Click(object sender,EventArgs e)
   {
      //Constructor for the custom Uri requires the onvif service address. 
      deviceUri = new UriBuilder("http:/onvif/device_service");

      //Sting manipulation: Need to check if our address contains a port. (Input validation)
      string[] addr = Adress.Text.Split(':');

      deviceUri.Host = addr[0];

      if (addr.Length == 2)
         deviceUri.Port = Convert.ToInt16(addr[1]);

      System.ServiceModel.Channels.Binding binding;
      HttpTransportBindingElement httpTransport = new HttpTransportBindingElement();
      httpTransport.AuthenticationScheme = System.Net.AuthenticationSchemes.Digest;
      binding = new CustomBinding(new TextMessageEncodingBindingElement(MessageVersion.soap12WSAddressing10,Encoding.UTF8),httpTransport);

      Device.DeviceClient device = new Device.DeviceClient(binding,new EndpointAddress(deviceUri.ToString()));
      Device.Service[] services = device.GetServices(false);

      Device.Service xmedia = services.FirstOrDefault(s => s.Namespace == "http://www.onvif.org/ver20.media/wsdl");

      if (xmedia != null)
      {
         media = new Media.Media2Client(binding,new EndPointAddress(deviceUri.ToString()));
         media.ClientCredentials.HttpDigest.ToString.ClientCredential.UserName = Login.Text;
         media.ClientCredentials.HttpDigest.ToString.ClientCredential.UserName = Login.Text;
         media.ClientCredentials.HttpDigest.AllowedImpresonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;

         profiles = media.GetProfiles(null,null);
         if (profiles != null)
            foreach (var p in profiles)
               listBox1.Items.Add(p.Name);

      }

      listBox1.SelectionChanged += OnSelectionChanged;
      video.MediaPlayer.VlcLibDirectoryneeded += MediaPlayer_VlcLibDirectoryNeeded;
      video.MediaPlayer.EndInit();


   }

   private void MediaPlayer_VlcLibDirectoryNeeded(object sender,Vlc.DotNet.Forms.VlcLibDirectoryNeededEventArgs e)
   {
      if (IntPtr.Size == 4)
      {
         e.VlcLibDirectory = new System.IO.DirectoryInfo(@"C:\Program Files\VideoLAN\VLC");
      }
   }

   private void OnSelectionChanged(object sender,RoutedEventArgs e)
   {
      if (profiles != null && listBox1.Selectedindex >=)
      {
         UriBuilder uri = new UriBuilder(media.GetStreamUri("RtspOverHttp",profiles[listBox1.Selectedindex].token));
         uri.Host = deviceUri.Host;
         uri.Port = deviceUri.Port;
         uri.Scheme = "rtsp";
         information.Text = uri.Path; ;
         string[] options = { ":rtsp-http",":rtps-http-port=" + uri.Port,":rtsp-user=" + Login.Text,":rtsp-pwd=" + passwordBox.Password };

         video.MediaPlayer.Play(uri.Uri,options);

      }
   }
}

解决方法

DeviceMedia都是项目中的命名空间,其类是从您引用的Web服务自动生成的。当您通过参考>添加服务参考添加服务参考时,Visual Studio将使用 WCF Web服务参考工具从WSDL元数据中为WCF客户端代理创建源代码,这样就可以访问该服务。

WSDL或 Web服务描述语言是用于描述Web服务接口的基于XML的语言,您可以在本教程中找到它们:

EndpointAddress类位于System.ServiceModel程序集中,您可能在其中输入了错字。但是,它也有一个名为System.Private.ServiceModel的NuGet程序包,但是您不需要它。来自EndpointAddress的{​​{3}}:

提供客户端用于与服务端点进行通信的唯一网络地址。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...