如何解决找不到媒体和设备对象或名称空间
我对C#还是很陌生,并且正在尝试编写一个基本程序来通过Onvif摄像头设备传输视频。我几乎能够了解并了解this 8 min tutorial。
但是有些事情我不知道。即使在添加了Vlc引用和两个Onvif服务引用之后,仍有一些代码无法编译。该教程很难遵循,因为他跳过了主要步骤。我正在尝试确定以下代码中的Device
和Media
&EndPointAddress
代表什么(根据他的教程)。
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);
}
}
}
解决方法
Device
和Media
都是项目中的命名空间,其类是从您引用的Web服务自动生成的。当您通过参考>添加服务参考添加服务参考时,Visual Studio将使用 WCF Web服务参考工具从WSDL元数据中为WCF客户端代理创建源代码,这样就可以访问该服务。
WSDL或 Web服务描述语言是用于描述Web服务接口的基于XML的语言,您可以在本教程中找到它们:
-
Device
界面-参见https://www.onvif.org/ver10/device/wsdl/devicemgmt.wsdl 的定义
-
Media
界面-参见https://www.onvif.org/ver20/media/wsdl/media.wsdl 的定义
EndpointAddress
类位于System.ServiceModel
程序集中,您可能在其中输入了错字。但是,它也有一个名为System.Private.ServiceModel
的NuGet程序包,但是您不需要它。来自EndpointAddress
的{{3}}:
提供客户端用于与服务端点进行通信的唯一网络地址。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。