i am new in ruby and rails i want to send a soap request using "savon" gem but it provide operations empty when i run this client.operations, here is my code
I am using Savon 2.3.0
ruby 2.1.0
Here is documentation of savon 2.3.0
http://rubydoc.info/gems/savon/frames
client = Savon.client(wsdl: 'https://webservice.kareo.com/services/soap/2.1/KareoServices.svc?wsdl',
:ssl_verify_mode => :none,
log: true,
pretty_print_xml: true)
puts client.operations
Thanks for help
You don't really need that. Try to call a function from your service. If that doesn't work then download SoapUI and try to create a successful call from SoapUI to your service.
In a next step you build ruby code which creates the same request as the one from SoapUI.
If that doesn't work for your come back and ask again.
Related
ArgumentError in Users::OmniauthCallbacksController#google_oauth2
header field value cannot include CR/LF
Really unsure where this error is coming from.
I'm using ruby 2.5, Rails 5, and google-api-client 0.8.2
Any ideas how to fix or what information I can provide to make this question more informative?
Update: My logs show this when I am trying to authorize with Google's API
Google::APIClient::Request Sending API request get https://www.googleapis.com/discovery/v1/apis/calendar/v3/rest {"User-Agent"=>"hello U/1.0.0 google-api-ruby-client/0.8.2 Mac OS X/10.13.4\n (gzip)", "Accept-Encoding"=>"gzip", "Content-Type"=>""}
And from my research, CRLF is "\r\n" characters, right?
So "User-Agent"=>"hello U/1.0.0 google-api-ruby-client/0.8.2 Mac OS X/10.13.4\n
is probably the issue.
So my question would be- how do I access User Agent in my request to fix this issue with Rails 5?
When using the Google::APIClient, the generated User-Agent may contains a CRLF. It can can be overridden in constructor. Example :
Google::APIClient.new(application_name: 'Foo', application_version: '1.0', user_agent: 'Foo/1.0 google-api-ruby-client/0.8.6 Linux/4.15.0-65-generic (gzip)')
You can modify the user_agent string to remove the CR/LF. I am using Rails 4.1.8 and google-api-client version `
#api_client = Google::APIClient.new(:application_name=>"Chronos", :application_version=>0)
# work around a bug that puts a CR/LF in the user agent string
#api_client.user_agent = #api_client.user_agent.gsub("\n", "")
Update gem google-api-client to version 0.20.0. It solves the problem but requires other changes to the application
Updating the version of the google-api-client gem did the trick for me.
I am using savon gem for integrating paysbuy in my project which is made in Ruby on Rails. This is how I am creating the savon client
client = Savon.client do
endpoint "https://www.paysbuy.com/receiveresponse/Result.aspx"
namespace "https://www.paysbuy.com/receiveresponse/ResultReg.aspx"
wsdl "https://demo.paysbuy.com/api_paynow/api_paynow.asmx"
end
logger.info"%%%%%%%%%%%%%%%%%#{client.operations}%%%%%%%%%%%%%%5555555"
But the response for "client.operations" is coming as "[]". I need help for rectifying anything wrong doing in my side. Thanks in advance for any help.
I assume you use Savon 2.x?
The syntax of your call is not correct. You need a parameter list not a block.
You also mix WSDL with WSDL less calling convention. You either specify
wsdl:
or
endpoint: ...
namespace: ...
client.operations doesn't work because you didn't give it a correct wsdl url.
Giving that's a MS based interface it is safe to assume that you can retrieve the WSDL with the parameter ?WSDL at the URL. Try this:
client = Savon.client(
wsdl: "https://demo.paysbuy.com/api_paynow/api_paynow.asmx?wsdl",
log: true,
log_level: debug,
pretty_print_xml: true
)
print client.operations
Unfortunately that call fails using Savon. I suspect it can't interpret the WSDL document.
What you can do is to use SoapUI to inspect your service and build a client without a WSDL.
client = Savon.client(
endpoint: "https://demo.paysbuy.com/api_paynow/api_paynow.asmx",
namespace: "http://tempuri.org",
log: true,
log_level: debug,
pretty_print_xml: true
)
I read the WSDL and found something which might be the namespace, but that can be tricky. Sometimes it needs some tinkering to find the correct request.
When you've found a working request using SoapUI, you need to translate it into Ruby code to make it work. That was always my approach at least.
Feel free to ask when you've reached that point.
Hello there I am testing few web services and I am trying to write a client using SAVON with my WSDL. I have one available operation named log_process and I am trying to access that but getting errors. I have a similar script written in PHP and it is working fine. I have tried
require 'net/http'
require "uri"
require 'savon'
client = Savon.client(wsdl: "http://somedomain.com/projects/shared/abc.wsdl")
#a=client.operations
puts #a
ary={0 =>"art", 1 =>"bac", 2 =>"arr"}
#result = client.call(:log_process, message:{0 =>"asdf", 1 =>"qwer", 2 =>"arr"})
puts #result
and getting following error
raise_soap_and_http_errors!': (SOAP-ENV:Client) Bad Request (Savon::SOAPFault)
My php working solution looks like this
$result = $client->log_process(array(0=>$user_name,1=>$user_pwd,2=>$display_type));
any idea what will be the ruby equivalent to this or am I calling the operation in correct manner?
I know this is late, but I was having the exact same issue trying to set up a soap request using savon to a soap server I have worked with extensively using PHP Soap server. I found another post related to this, and it seem that adding the message_tag option fixed it.
This is because in my case the WSDL was expecting functionNameRequest in the xml, but savon as only sending funcionName by setting message_tag to functionNameRequest the >soap server was able to correctly map the function that was being requested.
This was the thread that helped me out https://github.com/savonrb/savon/issues/520 Relevant code quoted below:
Hi,
I'm just sharing this in case it's useful.
I'm using savon 2.3.0 and I guess the gem had some problems identifying parameters >automatically from my wsdl. I have no idea about SOAP and this is the first time I'm >actually using it.
I'm dealing with TradeTracker's WSDL
With the following code I got it working:
client = Savon.client do
wsdl "http://ws.tradetracker.com/soap/affiliate?wsdl"
namespace_identifier :ns1
end
credentials = {
customerID: 123123,
passphrase: "123123123"
}
response = client.call(:authenticate, message_tag: :authenticate, message: credentials)
Try:
#result = client.call(:log_process, message:["asdf", "asg", "arr"])
In the PHP code, you are sending only 1 parameter, its an array
I'm using Savon library to get some SOAP requests work. And i'm using almost the same code within IRB and Rails application. When i'm running IRB everything works as it should, but Rails generate error "no method 'to_hash' for nil:NilClass" inside savon's do_request -> respond_with methods.
Here's my code (the same when running it within IRB or Rails):
# setup Savon client for SOAP requests
client = Savon::Client.new "http://www.webservicex.net/country.asmx?WSDL"
# test if "webservicex.net" server is up and running
actions = client.wsdl.soap_actions
raise "SOAP server is down" if actions.nil? or actions.length <= 0
# get country list
resp = client.request :get_countries
raise "No response for countries" if resp.nil?
resp = resp[:get_countries_response][:get_countries_result]
None of that exceptions is risen nor code far than 'pinging server' is executed.
What's wrong and how could i fix that?
It's problem with httpi gem - https://github.com/rubiii/savon/issues/163
Just use 0.9.1 version.
I have been trying to connect to a web service that is using digest authentication.
I am able to connect in Safari using user:password#service.site.com/endpoint
I have tried in Ruby and Rails to connect using HTTParty and Net:HTTP using the "basic"auth" options, but have not had any luck.
Wondering if the HTTParty/Net:HTTP "basic_auth" option is not going to be compatible with a "digest auth" service?
If not, is there another way that I might connect?
HTTParty basic auth is apparently not compatible with digest_auth. I found this Net:HTTP extension: https://codesnippets.joyent.com/posts/show/1075 and am writing a method to handle this, with the help of the Crack gem http://github.com/jnunemaker/crack:
def self.decode vin
url = URI.parse(APP_CONFIG[:vinlink_url])
Net::HTTP.start(url.host) do |http|
res = http.head(url.request_uri)
req = Net::HTTP::Get.new("/report?type=basic&vin=#{vin}")
req.digest_auth(APP_CONFIG[:vinlink_login], APP_CONFIG[:vinlink_password], res)
#response = http.request(req)
end
if #response.code == "200"
hash = Crack::XML.parse(#response.body).recursive_downcase_keys!.recursive_symbolize_keys!
end
end
Wasn't able to get to the codesnippets link given above today, but code is also available here https://gist.github.com/73102. I've used this successfully for digest authentication, but ran into problems with multiple request, getting 'Stale client nonce' errors - resolved by generating a new nonce within the digest_auth function each time it was called. Didn't find much on that when I looked, so hope this helps someone.