Defining DeviceClient(Bind, endPointAddress)

五迷三道 提交于 2019-12-12 00:15:33

问题


I am trying to interface with ONVIF certified equipment, like being able to access simple device information.

I have been trying to use the following code, provided by another member here:

ONVIF Authentication in .NET 4.0 with Visual Studios 2010

However, am having trouble understanding what the function DeviceClient is and what it does. I have tried to find it on the ONVIF WSDLs and as a class, but with no avail. Am very new to C#, WSDLs and ONVIF, and as such appreciate any help.

Thanks in advance!


回答1:


I was stuck with similar issue when my code was unable to recognize DeviceClient and MediaClient classes. From Hugo's comments I got the clue and removed OnVif references from my C# project which I'd already added as Web References. Then simply added following references as Service References and it worked for me:

  1. http://www.onvif.org/onvif/ver10/device/wsdl/devicemgmt.wsdl
  2. http://www.onvif.org/onvif/ver10/media/wsdl/media.wsdl

Below is the working code snippet I took from another post on StackOverflow.

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);



回答2:


I convert devicemngmnt.wsdl file to .cs file using vs2010 command promt but codefile does not contain "deviceclient".
Also I tried to add your xml snippet to .wsdl file and when I triy to convert .wsdl to .cs file by using VS2010 command prompt I get this error.

Error: Unable to import binding 'DeviceBinding' from namespace 'http://www.onvif.org/ver10/device/wsdl'.

  • Unable to import operation 'GetServices'.

  • The datatype 'http://www.onvif.org/ver10/schema:OnvifVersion' is missing.




回答3:


After banging my head several times I finally realized my problem.

I had to add a service to the wsdl, in the format:

   <wsdl:service name="DeviceService">
     <wsdl:port name="DevicePort" binding="tds:DeviceBinding">
       <soap:address location="http://ip/onvif/device_service"/>
     </wsdl:port>
   </wsdl:service>

After that it was just a matter of adding it to the project as a Service Reference, instead of a Web Reference. After that the library picked up the DeviceClient(Bind, endPoint) reference.

Hope this helps people out.



来源:https://stackoverflow.com/questions/11091492/defining-deviceclientbind-endpointaddress

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!