【发布时间】:2016-09-05 06:37:43
【问题描述】:
我试图从 onvif 设备获取实时流,我的程序搜索并成功找到了摄像机 IP 和 onvif 端口,但在下一步获取设备信息时我遇到了这个错误:
http://192.168.1.89/onvif/device_service 上没有可以接受消息的端点侦听。这通常是由不正确的地址或 SOAP 操作引起的。
我不知道我的代码有什么问题,即使我想从设备上获取时间和日期,也有同样的错误! 我的代码是:
private Device deviceChannel = null;
private System.ServiceModel.Channels.Binding binding = null;
private string serverNetworkAddress;
private string serviceAddress;
private string serverUsername = "";
private string serverPassword = "";
InitializeComponent();
serverUsername = OnvifUserTextBox.Text;
serverPassword = OnvifPwdTextBox.Text;
serverNetworkAddress = serverAddrTextBox.Text;
serviceAddress = string.Format("http://{0}/onvif/device_service", serverNetworkAddress);
//Create Binding
binding = CreateBinding();
private static System.ServiceModel.Channels.Binding CreateBinding()
{
HttpTransportBindingElement httpTransport = new HttpTransportBindingElement();
TransportSecurityBindingElement transportSecurity = new TransportSecurityBindingElement();
transportSecurity.EndpointSupportingTokenParameters.SignedEncrypted.Add(
new UsernameTokenParameters());
transportSecurity.AllowInsecureTransport = true;
transportSecurity.IncludeTimestamp = false;
TextMessageEncodingBindingElement me =
new TextMessageEncodingBindingElement(MessageVersion.Soap12, Encoding.UTF8);
return new CustomBinding(transportSecurity, me, httpTransport);
}
private static TChannel GetChannel<TChannel> (System.ServiceModel.Channels.Binding binding,
string serviceAddressText,
string serverUsername,
string serverPassword)
{
EndpointAddress serviceAddress = new EndpointAddress(serviceAddressText);
ChannelFactory<TChannel> channelFactory =
new ChannelFactory<TChannel>(binding, serviceAddress);
// configure the username credentials on the channel factory
UsernameClientCredentials credentials =
new UsernameClientCredentials(new UsernameInfo(serverUsername, serverPassword));
// replace ClientCredentials with UsernameClientCredentials
channelFactory.Endpoint.Behaviors.Remove(typeof(ClientCredentials));
channelFactory.Endpoint.Behaviors.Add(credentials);
return channelFactory.CreateChannel();
}
private void button2_Click(object sender, EventArgs e)
{
//getting the device information
listBox.Items.Clear();
serverUsername = OnvifUserTextBox.Text;
serverPassword = OnvifPwdTextBox.Text;
serverNetworkAddress = serverAddrTextBox.Text;
serviceAddress = string.Format("http://{0}/onvif/device_service", serverNetworkAddress);
// string model, firmwareVersion, serialNumber, hardwareId;
try
{
// Create a client with given client endpoint configuration
deviceChannel =
GetChannel<Device>(binding, serviceAddress, serverUsername, serverPassword);
// deviceChannel.GetDeviceInformation= ( out model, out FirmwareVersion, out SerialNumber, out HardwareId);
//get date and time
var timemamo = deviceChannel.GetSystemDateAndTime();
listBox.Items.Add(timemamo);
var info = deviceChannel.GetDeviceInformation(new GetDeviceInformationRequest());
//MessageBox.Show(string.Format("Model: {0}", info.Model));
string strManuf = string.Format("Manufacturer: {0}", info.Manufacturer);
listBox.Items.Add(strManuf);
string strModel = string.Format("Model: {0}", info.Model);
listBox.Items.Add(strModel);
string strFw = string.Format("Firmware Version: {0}", info.FirmwareVersion);
listBox.Items.Add(strFw);
string strSerialNo = string.Format("Serial Number: {0}", info.SerialNumber);
listBox.Items.Add(strSerialNo);
string strHwId = string.Format("Hardware Id: {0}", info.HardwareId);
listBox.Items.Add(strHwId);
}
catch (Exception exception)
{
string str = string.Format("GetDeviceInformation():mamo " + exception.Message);
listBox.Items.Add(str);
}
}
【问题讨论】:
-
什么是 UsernameTokenParameters?它属于任何 .NET Framework 库吗?
标签: soap wsdl video-streaming ip-camera onvif