Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ONVIF Camera (Axis) returning InvalidArgs when sending request with Savon #971

Open
migalenkom opened this issue May 27, 2022 · 4 comments

Comments

@migalenkom
Copy link

migalenkom commented May 27, 2022

Bug report

Current behavior:

We are using the official ONVIF tool and it is generating this request which is working correctly:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:tev="http://www.onvif.org/ver10/events/wsdl">
  <SOAP-ENV:Header>
    <wsa:Action>http://www.onvif.org/ver10/events/wsdl/PullPointSubscription/PullMessagesRequest</wsa:Action>
    <wsa:To>http://192.168.3.102/onvif/services</wsa:To>
    <dom0:SubscriptionId xmlns:dom0="http://www.example.com/2009/event">6</dom0:SubscriptionId>
  </SOAP-ENV:Header>
  <SOAP-ENV:Body>
    <tev:PullMessages>
      <tev:Timeout>PT5S</tev:Timeout>
      <tev:MessageLimit>1</tev:MessageLimit>
    </tev:PullMessages>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

We are trying to replicate the same with Savon, we are using this code:

require 'savon'

@ip.           = 'ip'
@user        = 'user'
@pass.      = 'pass'
@wsdl        = 'http://www.onvif.org/ver10/events/wsdl/event.wsdl'
@endpoint = 'http://192.168.11.64/onvif/event_service'
      
@soap_client = Savon.client do |c|
  c.wsdl wsdl
  c.endpoint @endpoint
  c.digest_auth(user, pass)
  c.use_wsa_headers true
  c.convert_request_keys_to :none
  c.env_namespace 'SOAP-ENV'
  c.open_timeout 60
  c.read_timeout 60
  c.soap_version 2
  c.headers 'Content-Type' => 'application/soap+xml; charset=utf-8'
  c.pretty_print_xml true
end
@soap_client.call(:pull_messages)

This code is generating this XML, which looks a little different:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tev="http://www.onvif.org/ver10/events/wsdl" xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" xmlns:wsdl="http://docs.oasis-open.org/wsn/b-2" xmlns:dom0="http://www.example.com/2009/event">
  <SOAP-ENV:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
    <dom0:SubscriptionId>30</dom0:SubscriptionId>
    <wsa:Action>http://www.onvif.org/ver10/events/wsdl/PullPointSubscription/PullMessagesRequest</wsa:Action>
    <wsa:To>http://192.168.3.102/onvif/services</wsa:To>
    <wsa:MessageID xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing">urn:uuid:18cab322-913c-4270-9984-a8e801b95e14</wsa:MessageID>
  </SOAP-ENV:Header>
  <SOAP-ENV:Body>
    <tev:PullMessages>
      <tev:MessageLimit>1</tev:MessageLimit>
      <tev:Timeout>PT5S</tev:Timeout>
    </tev:PullMessages>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

When we send the SAVON version of the XML, the camera returns:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:c14n="http://www.w3.org/2001/10/xml-exc-c14n#" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsa5="http://www.w3.org/2005/08/addressing" xmlns:wsrfbf="http://docs.oasis-open.org/wsrf/bf-2" xmlns:wstop="http://docs.oasis-open.org/wsn/t-1" xmlns:tt="http://www.onvif.org/ver10/schema" xmlns:wsrfr="http://docs.oasis-open.org/wsrf/r-2" xmlns:tev1="http://www.onvif.org/ver10/events/wsdl/NotificationProducerBinding" xmlns:tev2="http://www.onvif.org/ver10/events/wsdl/EventBinding" xmlns:tev3="http://www.onvif.org/ver10/events/wsdl/SubscriptionManagerBinding" xmlns:wsnt="http://docs.oasis-open.org/wsn/b-2" xmlns:tev4="http://www.onvif.org/ver10/events/wsdl/PullPointSubscriptionBinding" xmlns:tev="http://www.onvif.org/ver10/events/wsdl" xmlns:tns1="http://www.onvif.org/ver10/topics" xmlns:tnsaxis="http://www.axis.com/2009/event/topics" xmlns:ter="http://www.onvif.org/ver10/error">
  <SOAP-ENV:Header>
    <wsa5:RelatesTo>urn:uuid:a8271a37-60e5-47ea-a6ac-bfb988368da4</wsa5:RelatesTo>
    <wsa5:To SOAP-ENV:mustUnderstand="true">http://www.w3.org/2005/08/addressing/anonymous</wsa5:To>
  </SOAP-ENV:Header>
  <SOAP-ENV:Body>
    <SOAP-ENV:Fault>
      <SOAP-ENV:Code>
        <SOAP-ENV:Value>SOAP-ENV:Sender</SOAP-ENV:Value>
        <SOAP-ENV:Subcode>
          <SOAP-ENV:Value>ter:InvalidArgs</SOAP-ENV:Value>
        </SOAP-ENV:Subcode>
      </SOAP-ENV:Code>
      <SOAP-ENV:Reason>
        <SOAP-ENV:Text xml:lang="en"/>
      </SOAP-ENV:Reason>
    </SOAP-ENV:Fault>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Do you have any ideas about what could be causing the issue? - We are tearing our hair out, thank you!

Steps to reproduce current behavior:

Expected behavior:
request passed OK

System information:

  • ruby version: 3.1
  • savon version: 2.12.1
@migalenkom migalenkom changed the title Onvif Camera returns invalid args when sending request with SAVON ONVIF Camera (Axis) returning InvalidArgs when sending request with Savon May 27, 2022
@Dounx
Copy link

Dounx commented Nov 10, 2022

@michaelklishin Do you find any solution?

@migalenkom
Copy link
Author

Hi, @Dounx as far as I remember there needs to add namespaces.

{ namespaces: { 'xmlns:wsdl' => "http://docs.oasis-open.org/wsn/b-2",
                'xmlns:dom0' => "http://www.axis.com/2009/event" } 
}

@Dounx
Copy link

Dounx commented Nov 10, 2022

Where to add this namespaces?

I am trying to call some ONVIF PTZ Interface

class PTZClient
  attr_reader :client

  def initialize(endpoint, username, password)
    @client = Savon.client do |c|
      c.wsdl "https://www.onvif.org/ver20/ptz/wsdl/ptz.wsdl"
      c.endpoint endpoint
      c.wsse_auth(username, password, :digest)
    end
  end

  def presets(token)
    client.call(:get_presets, message: { profile_token: token })
  end
end

tokens = ["profileToken1"]
endpoint = "xxx"
username = "xxx"
password = "xxx"

ptz_client = PTZClient.new(endpoint, username, password)
presets = ptz_client.presets(tokens.first)
p presets

But I also get this error: (env:Sender) the parameter value is illegal (Savon::SOAPFault)

Any idea?

@Dounx
Copy link

Dounx commented Nov 10, 2022

OK, It's my code issue.

I forget add convert_request_keys_to :camelcase option

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants