我有 3 台 ONVIF 摄像机(博世、松下和 AXIS)。我使用 WS-Discovery 找到相机,并且可以使用 GetDeviceInformation 从相机获取信息。我的问题是,当我尝试从中获取信息时,AXIS 相机返回 (400) Bad Request,另外两个相机就像一个魅力。
我已经从 SourceForge 安装了 ONVIF 设备管理器。如果我在程序中输入登录凭据,我可以从 AXIS 摄像机流式传输实时视频。如果我不输入任何登录凭据,我可以找到摄像头,但无法流式传输任何视频。因此,基于此,我得出结论,相机配置正确。
我认为这与绑定上的登录凭据有关,但无法弄清楚出了什么问题。
我的代码看起来像这样
private void CustomBinding2()
{
try
{
const string SERVICE_ADDRESS_DIRECT = "http://192.168.1.72/onvif/device_service"; //400 bad request
const string USERNAME = "cbk";
const string PASSWORD = "12";
HttpTransportBindingElement httpTransportBindingElement = new HttpTransportBindingElement();
httpTransportBindingElement.MaxReceivedMessageSize = Int32.MaxValue;
httpTransportBindingElement.KeepAliveEnabled = false;
httpTransportBindingElement.MaxBufferSize = Int32.MaxValue;
httpTransportBindingElement.ProxyAddress = null;
httpTransportBindingElement.BypassProxyOnLocal = true;
httpTransportBindingElement.UseDefaultWebProxy = false;
httpTransportBindingElement.TransferMode = TransferMode.StreamedResponse;
httpTransportBindingElement.AuthenticationScheme = AuthenticationSchemes.Basic;
TextMessageEncodingBindingElement messegeElement = new TextMessageEncodingBindingElement();
messegeElement.MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.None);
CustomBinding binding = new CustomBinding(messegeElement, httpTransportBindingElement);
binding.CloseTimeout = TimeSpan.FromSeconds(30.0);
binding.OpenTimeout = TimeSpan.FromSeconds(30.0);
binding.SendTimeout = TimeSpan.FromMinutes(10.0);
binding.ReceiveTimeout = TimeSpan.FromMinutes(3.0);
EndpointAddress serviceAddress = new EndpointAddress(SERVICE_ADDRESS_DIRECT);
ChannelFactory<Device> channelFactory = new ChannelFactory<Device>(binding, serviceAddress);
channelFactory.Credentials.UserName.UserName = USERNAME;
channelFactory.Credentials.UserName.Password = PASSWORD;
Device channel = channelFactory.CreateChannel();
string model, firmwareVersion, serialNumber, hardwareId;
channel.GetDeviceInformation(out model, out firmwareVersion, out serialNumber, out hardwareId);
MessageBox.Show(string.Format("Model: {0}", model));
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}