问题
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:
- http://www.onvif.org/onvif/ver10/device/wsdl/devicemgmt.wsdl
- 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