Вопрос

I'm forced to enter the world of soap and having a bit of an issue, using Savon.

The wsdl is: http://evernet.nwmls.com/evernetqueryservice/evernetquery.asmx?wsdl And if I use the test form for this data provider, I'm able to receive data without error using the following format:

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<EverNetQuerySpecification xmlns="urn:www.nwmls.com/Schemas/General/EverNetQueryXML.xsd">
  <Message>
<Head>
  <UserId>my_username_here</UserId>
  <Password>my_password_here</Password>
  <SchemaName>StandardXML1_2</SchemaName>
</Head>
<Body>
  <Query>
    <MLS>nwmls</MLS>
    <PropertyType>RESI</PropertyType>
    <BeginDate>2014-04-20T00:25:00</BeginDate>
    <EndDate>2014-04-22T00:25:00</EndDate>
  </Query>
  <Filter />
</Body>

What I'm trying to do with Savon 2.2 to replicate this in my rails app is:

client = Savon.client(:wsdl => "http://evernet.nwmls.com/evernetqueryservice/evernetquery.asmx?wsdl")

response = client.call(:retrieve_listing_data) do |locals|
    locals.message "Query" => {"Head" => {"UserId" => "my_username_here", "Password" => "my_password_here", "SchemaName" => "StandardXML1_2"}, "Body" => {"MLS" => "nwmls", "PropertyType" => "RESI", "BeginDate" => "2014-04-17T00:25:00", "EndDate" => "2014-04-22T00:25:00"}}
end

But I'm getting an error saying:

Value cannot be null. Parameter name: s

I'm a little bit lost in anything soap, but especially lost here because it seems that I'm including everything in my Savon syntax but must be missing something...

Edit: here's the full xml response with debugging on:

D, [2014-04-22T16:55:52.806716 #77213] DEBUG -- : HTTPI GET request to evernet.nwmls.com (net_http)
I, [2014-04-22T16:55:54.340990 #77213]  INFO -- : SOAP request: http://evernet.nwmls.com/evernetqueryservice/evernetquery.asmx
I, [2014-04-22T16:55:54.341077 #77213]  INFO -- : SOAPAction: "http://www.nwmls.com/EverNetServices/RetrieveListingData", Content-Type: text/xml;charset=UTF-8, Content-Length: 682
D, [2014-04-22T16:55:54.341120 #77213] DEBUG -- : <?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="http://www.nwmls.com/EverNetServices" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"><env:Body><tns:RetrieveListingData><tns:Query><tns:Head><tns:Head>hoverboard</tns:Head><tns:Password>cP6cHias</tns:Password><tns:SchemaName>StandardXML1_2</tns:SchemaName></tns:Head><tns:Body><tns:MLS>nwmls</tns:MLS><tns:PropertyType>RESI</tns:PropertyType><tns:BeginDate>2014-04-17T00:25:00</tns:BeginDate><tns:EndDate>2014-04-22T00:25:00</tns:EndDate></tns:Body></tns:Query></tns:RetrieveListingData></env:Body></env:Envelope>
D, [2014-04-22T16:55:54.341255 #77213] DEBUG -- : HTTPI POST request to evernet.nwmls.com (net_http)
I, [2014-04-22T16:55:54.678125 #77213]  INFO -- : SOAP response (status 200)
D, [2014-04-22T16:55:54.678292 #77213] DEBUG -- : <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><RetrieveListingDataResponse xmlns="http://www.nwmls.com/EverNetServices"><RetrieveListingDataResult>&lt;Listings&gt;
  &lt;ResponseMessages&gt;
    &lt;Message&gt;Value cannot be null.
Parameter name: s&lt;/Message&gt;
  &lt;/ResponseMessages&gt;
&lt;/Listings&gt;</RetrieveListingDataResult></RetrieveListingDataResponse></soap:Body></soap:Envelope>
 => #<Savon::Response:0x007f844230e4e0 @http=#<HTTPI::Response:0x007f844230fc00 @code=200, @headers={"cache-control"=>"private, max-age=0", "content-type"=>"text/xml; charset=utf-8", "server"=>"Microsoft-IIS/7.5", "x-aspnet-version"=>"4.0.30319", "x-powered-by"=>"ASP.NET", "date"=>"Tue, 22 Apr 2014 23:55:54 GMT", "content-length"=>"574"}, @raw_body="<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><soap:Body><RetrieveListingDataResponse xmlns=\"http://www.nwmls.com/EverNetServices\"><RetrieveListingDataResult>&lt;Listings&gt;\r\n  &lt;ResponseMessages&gt;\r\n    &lt;Message&gt;Value cannot be null.\r\nParameter name: s&lt;/Message&gt;\r\n  &lt;/ResponseMessages&gt;\r\n&lt;/Listings&gt;</RetrieveListingDataResult></RetrieveListingDataResponse></soap:Body></soap:Envelope>", @body="<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><soap:Body><RetrieveListingDataResponse xmlns=\"http://www.nwmls.com/EverNetServices\"><RetrieveListingDataResult>&lt;Listings&gt;\r\n  &lt;ResponseMessages&gt;\r\n    &lt;Message&gt;Value cannot be null.\r\nParameter name: s&lt;/Message&gt;\r\n  &lt;/ResponseMessages&gt;\r\n&lt;/Listings&gt;</RetrieveListingDataResult></RetrieveListingDataResponse></soap:Body></soap:Envelope>">, @globals=#<Savon::GlobalOptions:0x007f8447489a40 @option_type=:global, @options={:encoding=>"UTF-8", :soap_version=>1, :namespaces=>{}, :logger=>#<Logger:0x007f84474899c8 @progname=nil, @level=0, @default_formatter=#<Logger::Formatter:0x007f84474899a0 @datetime_format=nil>, @formatter=nil, @logdev=#<Logger::LogDevice:0x007f8447489950 @shift_size=nil, @shift_age=nil, @filename=nil, @dev=#<IO:<STDOUT>>, @mutex=#<Logger::LogDevice::LogDeviceMutex:0x007f8447489928 @mon_owner=nil, @mon_count=0, @mon_mutex=#<Mutex:0x007f84474898d8>>>>, :log=>true, :filters=>[], :pretty_print_xml=>false, :raise_errors=>true, :strip_namespaces=>true, :convert_response_tags_to=>#<Proc:0x007f8447489860@/Users/seth/.rvm/gems/ruby-2.0.0-p195/gems/savon-2.4.0/lib/savon/options.rb:56 (lambda)>, :multipart=>false, :wsdl=>"http://evernet.nwmls.com/evernetqueryservice/evernetquery.asmx?wsdl"}>, @locals=#<Savon::LocalOptions:0x007f84443732a8 @option_type=:local, @options={:advanced_typecasting=>true, :response_parser=>:nokogiri, :multipart=>false, :message=>{"Query"=>{"Head"=>{"Head"=>"my_username", "Password"=>"my_password", "SchemaName"=>"StandardXML1_2"}, "Body"=>{"MLS"=>"nwmls", "PropertyType"=>"RESI", "BeginDate"=>"2014-04-17T00:25:00", "EndDate"=>"2014-04-22T00:25:00"}}}}>> 
Это было полезно?

Решение 2

have you looked into the resulting XML message?

you should set the parameters

log => true,
log_level => :debug,
pretty_print_xml => true

and have a look.

Другие советы

I recently dealt with this same problem. NWMLS uses a special root key called v_strXmlQuery that includes a nested XML string. This works just fine for me:

[1] pry(main)> require 'savon'
=> true
[2] pry(main)> client = Savon.client(
[2] pry(main)*   wsdl: "http://evernet.nwmls.com/evernetqueryservice/evernetquery.asmx?wsdl",
[2] pry(main)* convert_request_keys_to: :none); # this is important
=> #<Savon::Client:0x007fbf5a324288
  ...
[4] pry(main)> username = 'myusername'
[5] pry(main)> password = 'mypassword'
[7] pry(main)> message =  {v_strXmlQuery:"<?xml version=\"1.0\" encoding=\"UTF-8\"?><EverNetQuerySpecification xmlns=\"urn:www.nwmls.com/Schemas/General/EverNetQueryXML.xsd\"><Message><Head><UserId>#{username}</UserId><Password>#{password}</Password><SchemaName>#{schema_name}</SchemaName></Head><Body><Query><MLS>NWMLS</MLS><PropertyType>RESI</PropertyType><Status>A</Status><County>King</County><City>Seattle</City><BeginDate>2005-08-27T16:14:09</BeginDate><EndDate>2015-08-28T09:14:09</EndDate></Query><Filter></Filter></Body></Message></EverNetQuerySpecification>"}y><BeginDate>2005-08-27T16:14:09</BeginDate><EndDate>2015-08-28T09:14:09</EndDate></Query><Filter></Filter></Body></Message></EverNetQuerySpecification>"}
=> {:v_strXmlQuery=>
  "<?xml version=\"1.0\" encoding=\"UTF-8\"?><EverNetQuerySpecification xmlns=\"urn:www.nwmls.com/Schemas/General/EverNetQueryXML.xsd\"><Message><Head><UserId>myusername</UserId><Password>mypassword</Password><SchemaName>StandardXML1_3</SchemaName></Head><Body><Query><MLS>NWMLS</MLS><PropertyType>RESI</PropertyType><Status>A</Status><County>King</County><City>Seattle</City><BeginDate>2005-08-27T16:14:09</BeginDate><EndDate>2015-08-28T09:14:09</EndDate></Query><Filter></Filter></Body></Message></EverNetQuerySpecification>"}

[8] pry(main)> client.call(:retrieve_listing_data, message: message).body
...
=> {:retrieve_listing_data_response=>
  {:retrieve_listing_data_result=>
    "<Listings xmlns=\"http://www.nwmls.com/Schemas/Standard/StandardXML1_3.xsd\"><Residential>...<MR>Timeless, top of the line finish work in this studs-out craftsman remodel.  This remodel has everything desired in a home: open floor plan, rich hardwood flooring,...

I'd suggest using an XML builder like Savon's Gyoku gem to construct the sub hash and attach the xml header/footer, then inject it into the parent document query:

# takes a query hash and generates correctly-formatted SOAP-friendly XML
class QueryGenerator

  def self.call(hash)
    new.call(hash)
  end

  def call(hash)
    _xml = Gyoku.xml(hash, key_converter: :camelcase)
    repaired_xml = fix_weird_keys(_xml)
    wrapped_xml = xml_header + repaired_xml + xml_footer
    { v_strXmlQuery: wrapped_xml }
  end

  def xml_header
    "<?xml version=\"1.0\" encoding=\"UTF-8\"?><EverNetQuerySpecification xmlns=\"urn:www.nwmls.com/Schemas/General/EverNetQueryXML.xsd\"><Message>"
  end

  def xml_footer
    "</Message></EverNetQuerySpecification>"
  end

  # because its all Camelcase, except for that one that aint
  def fix_weird_keys(xml_str)
    xml_str.gsub('<Mls>','<MLS>').
            gsub('</Mls>','</MLS>')
  end
end

query_hash = {
  head: {
    user_id:     'myusername',
    password:    'mypassword',
    schema_name: 'StandardXML1_3'
  },
  body: {
    query: {
      mls: 'NWMLS',
      property_type: 'RESI',
      status: 'A',
      city: 'Seattle',
      begin_date: '2014-04-17T00:25:00',
      end_date: '2014-04-22T00:25:00'
    },
    filter: {}
  }
}
listing_data_query =  QueryGenerator.call(query_hash)
client.call(:retrieve_listing_data, message: listing_data_query )
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top