如何使用Ruby Savon调用SOAP Web服务?
我正在尝试使用Savon调用web服务。 我试图生成的请求如下(这是一个有效的请求,正在使用生成): 这是我的ruby客户端代码:如何使用Ruby Savon调用SOAP Web服务?,ruby,web-services,savon,Ruby,Web Services,Savon,我正在尝试使用Savon调用web服务。 我试图生成的请求如下(这是一个有效的请求,正在使用生成): 这是我的ruby客户端代码: require "savon" URL = 'http://localhost:8080/MockFraudValidationServiceProvider/services/FraudValidationServiceV3' begin client = Savon.client do # wsdl URL + "?wsdl"
require "savon"
URL = 'http://localhost:8080/MockFraudValidationServiceProvider/services/FraudValidationServiceV3'
begin
client = Savon.client do
# wsdl URL + "?wsdl"
endpoint URL
namespace "http://schemas.gid.gap.com/fraudvalidation/v3"
log_level :debug
pretty_print_xml :true
end
response = client.call(:validate_order,
message: {
FraudValidationRequest: { OrderHeader: { EntryType: 1 } }
}
)
puts response.to_hash;
end
我尝试过几种方法:wsdl、端点和名称空间、有无名称空间、camelcase等等,但我无法生成适当的请求。
我不是SOAP方面的专家(显然),我知道如果有WSDL(我的案例),就没有必要设置名称空间,但我不确定。当我尝试仅使用WSDL时,我得到以下结果:
<?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:types="http://services.gid.gap.com/fraudvalidation/v3"
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ins0="http://schemas.gid.gap.com/fraudvalidation/v3">
<env:Body>
<types:FraudValidationRequest>
<fraudValidationRequest>
<orderHeader>
<entryType>1</entryType>
</orderHeader>
</fraudValidationRequest>
</types:FraudValidationRequest>
</env:Body>
</env:Envelope>
1.
请给出建议,我希望我说得很清楚。你试过这个吗
require 'savon'
# create a client for the service
client = Savon.client(wsdl: 'http://service.example.com?wsdl')
p client.operations
# => [:find_user, :list_users]
# call the 'findUser' operation
response = client.call(:find_user, message: { id: 42 })
response.body
# => { find_user_response: { id: 42, name: 'Hoff' } }
客户端操作是您可以调用的操作,只需打印它们并检查以调用正确的操作即可。
message是一个客户端参数。如果您放置了参数,也可以通过以下方式进行设置:
params = {
:param_1 => "value",
_param_2 => 7
}
response = client.call(:find_user, message: params)
我使用了这段代码,并且能够调用我的Web服务您是否尝试过使用SoapUI手动创建SOAP调用?这将是一个起点。然后,您应该将正确的SOAP调用的XML文档共享到您的接口。
<?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:types="http://services.gid.gap.com/fraudvalidation/v3"
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ins0="http://schemas.gid.gap.com/fraudvalidation/v3">
<env:Body>
<types:FraudValidationRequest>
<fraudValidationRequest>
<orderHeader>
<entryType>1</entryType>
</orderHeader>
</fraudValidationRequest>
</types:FraudValidationRequest>
</env:Body>
</env:Envelope>
require 'savon'
# create a client for the service
client = Savon.client(wsdl: 'http://service.example.com?wsdl')
p client.operations
# => [:find_user, :list_users]
# call the 'findUser' operation
response = client.call(:find_user, message: { id: 42 })
response.body
# => { find_user_response: { id: 42, name: 'Hoff' } }
params = {
:param_1 => "value",
_param_2 => 7
}
response = client.call(:find_user, message: params)