2011-12-09 72 views
3

我完全卡在ONVIF驗證。我想我已經嘗試過所有的東西,或者至少幾乎所有東西,而且我在互聯網上找不到足夠的信息。我已創建使用SvcUtil工具,我的代碼做認證存根客戶(他們中的一個,因爲我已經嘗試了很多東西):使用軸卡馬拉P1344的Onvif驗證c#

string uri = "http://140.0.22.39/onvif/services"; 

EndpointAddress serviceAddressPrueba = new EndpointAddress(uri); 
HttpTransportBindingElement httpBinding = new HttpTransportBindingElement(); 
httpBinding.AuthenticationScheme = AuthenticationSchemes.Digest; 
var messegeElement = new TextMessageEncodingBindingElement(); 
messegeElement.MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.None); 
CustomBinding bindprueba = new CustomBinding(messegeElement, httpBinding); 
DeviceClient clientprueba = new DeviceClient(bindprueba, serviceAddressPrueba); 
string passwordDigestBase64; 
//HERE I PUT THE CODE TO ENCRYPT THE PASSWORD. 
PasswordDigestBehavior behavior1 = new PasswordDigestBehavior("root",passwordDigestBase64); 
clientprueba.Endpoint.Behaviors.Add(behavior1); 
string d1; 
string d2; 
string d3; 
string d4; 

clientprueba.GetDeviceInformation(out d1, out d2, out d3, out d4); 

在此之後有以下錯誤:

{"The remote server returned an unexpected response: (400) Bad Request."} 

如果你能幫我解決這個問題,我將非常非常感激。

+0

請檢查http://stackoverflow.com/questions/18149866/unable-to-connect-to-onvif-enabled-camera-using-c-sharp/18623888#18623888 – mhcuervo

回答

0

幾件事情可能會導致此:

  1. 你已經設置通過Web瀏覽器root密碼,從而鎖定用戶ONVIF。登錄到相機並添加一個ONVIF用戶(有一個專門的頁面)

  2. 您的密碼摘要只包含密碼,它應該包含隨機隨機數,創建時間和密碼的串聯。

  3. 您的本地時鐘與相機的時鐘不同步。調用getSystemDateAndTime來讀取遠程時鐘並記錄您之間的時間差異。

這些是3出來的那太慢了4點重要的事情(第4一個被導入WSDL,但它看起來像你得到它的話)

0

試試這個方法:

ServicePointManager.Expect100Continue = false; 
var endPointAddress = new EndpointAddress("http://" + cameraAddress + "/onvif/device_service"); 
var httpTransportBinding = new HttpTransportBindingElement { AuthenticationScheme = AuthenticationSchemes.Digest }; 
var textMessageEncodingBinding = new TextMessageEncodingBindingElement { MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.None) }; 
var customBinding = new CustomBinding(textMessageEncodingBinding, httpTransportBinding); 
var passwordDigestBehavior = new PasswordDigestBehavior(adminName, adminPassword); 
var deviceClient = new DeviceClient(customBinding, endPointAddress); 
deviceClient.Endpoint.Behaviors.Add(passwordDigestBehavior); 

請注意,將ServicePointManager.Expect100Continue設置爲false很重要。