ONVIF GetStreamURL C#

3.5k views Asked by At

I'm trying to get stream URL using ONVIF, and I'm stucked. Method GetStreamURL always returns Null, but when I'm sniffing traffic in wireshark I get correct responses from camera. Maybe someone had similar problem and can help me? My code looks like this:

HttpTransportBindingElement httpBinding = new HttpTransportBindingElement();
EndpointAddress serviceAddress = new EndpointAddress(__url);
TextMessageEncodingBindingElement messegeElement = new TextMessageEncodingBindingElement();

httpBinding.AuthenticationScheme = AuthenticationSchemes.Digest;
messegeElement.MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.WSAddressing10);

CustomBinding bind = new CustomBinding(messegeElement, httpBinding);
ONVIF.onvifMedia.mediaClient mclient = new ONVIF.onvifMedia.mediaClient(bind, serviceAddress);

ONVIF.onvifMedia.StreamSetup streamSetup = new ONVIF.onvifMedia.StreamSetup();
streamSetup.Stream = ONVIF.onvifMedia.StreamType.RTPUnicast;

streamSetup.Transport = new ONVIF.onvifMedia.Transport();
streamSetup.Transport.Protocol = ONVIF.onvifMedia.TransportProtocol.RTSP;

mediaUri uri = new mediaUri();
Profile[] profiles;

log.Debug("Trying to fetch profiles");
profiles = mclient.GetProfiles();

foreach (Profile item in profiles)
{
   uri = mclient.GetStreamUri(streamSetup, item.token);
}
1

There are 1 answers

0
Paweł Wojtal On BEST ANSWER

It looks like I helped myself and resolve this issue: code works great, but I need to delete all service references to wsdl files and add them again. I didn't find if there was any update of wsdls last time at ONVIF website, however - it helped me and now above code is working, and I get proper streaming URI.

There is one issue in this code, but in my opinion in depends how standard was implemented on device: some cameras returns streaming URI with HTTP prefix, but they transmit it only via RTSP.

If you want to use similar code don't forget to add login and password field to address.