title: ONVIF Authentication in .NET 4.0 with Visual Studios 2010
body: <p>My task is to try to establish a communication with a ONVIF camera in the building to, eventually, upgrade the company's domotic solution to automatically recognize ONVIF cameras and to be able to set them up and to use their services.</p>
  
  <p>I am already able to gather some basic informations like its model, its MAC address and its firmware version this way:</p>
  
  <pre><code>    EndpointAddress endPointAddress = new EndpointAddress("&lt;mycameraurl:&lt;mycameraport&gt;/onvif/device_service");
      CustomBinding bind = new CustomBinding("DeviceBinding");
      DeviceClient temp = new DeviceClient(bind, endPointAddress);
      String[] arrayString = new String[4];
      String res = temp.GetDeviceInformation(out arrayString[0], out arrayString[1], out arrayString[2], out  arrayString[3]);
      MessageBox.Show("Model " + arrayString[0] + ", FirmwareVersion " + arrayString[1] + ", SerialNumber " + arrayString[2] + ", HardwareId " + arrayString[3]);
  </code></pre>
  
  <p>I have this xml specification for the customBinding in my app.config file:</p>
  
  <pre><code>  &lt;customBinding&gt;
      &lt;binding name="DeviceBinding"&gt;
        &lt;textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
            messageVersion="Soap12" writeEncoding="utf-8"&gt;
          &lt;readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
              maxBytesPerRead="4096" maxNameTableCharCount="16384" /&gt;
        &lt;/textMessageEncoding&gt;
        &lt;httpTransport manualAddressing="false" maxBufferPoolSize="524288"
            maxReceivedMessageSize="65536" allowCookies="false" authenticationScheme="Anonymous"
            bypassProxyOnLocal="false" decompressionEnabled="true" hostNameComparisonMode="StrongWildcard"
            keepAliveEnabled="false" maxBufferSize="65536" proxyAuthenticationScheme="Anonymous"
            realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false"
            useDefaultWebProxy="true" /&gt;
      &lt;/binding&gt;
    &lt;/customBinding&gt;
  </code></pre>
  
  <p>My problem is that it's impossible for me to go deeper into what I can ask the camera. I get "400 - Bad request" errors for anything I try, and according to what I have read it's because I need to handle authentication for the camera.</p>
  
  <p>The problem is that, everything I find about WS-Security (which seems to be used by the ONVIF) is really, really confused, with a lot of different solutions, and nothing really working for me. For example, <a href="http://custforum.axis.com/viewtopic.php?p=4522&amp;sid=7990ea009d57544606efd627f3a40541" rel="nofollow noreferrer">this post here </a> make it sound very simple, but I've tried to create a UserNameSecurityToken and I still get 400 bad request errors. Since I don't know if that's because I've written my Token system wrong, if it's because the camera doesn't support what I try to do.</p>
  
  <p>I've already tried WSHttpBinding and putting it in Username mode, but using WSHttpBinding break the basic information discovery I was able to create (with a MustUnderstand error)...</p>
  
  <p>Any pointers for me? Simple WS-Security/.NET, C#/ONVIF tutorials, everything will be accepted.</p>