私は 3 台の ONVIF カメラ (Bosch、Pansonic、AXIS) を持っています。WS-Discovery を使用してカメラを見つけ、GetDeviceInformation を使用してカメラから情報を取得できます。私の問題は、AXIS カメラから情報を取得しようとすると、(400) Bad Request が返されることです。他の 2 つのカメラは魅力的に機能します。
SourceForge から ONVIF Device Manager をインストールしました。プログラムにログイン資格情報を入力すると、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);
}
}