Ruby on rails 根据给定的WSDL描述读取SOAP内容
我得到了一个wsdl的服务API,我从来没有这样做过,也不知道应该用它做什么 该文件描述了他们将向我们发送的内容:Ruby on rails 根据给定的WSDL描述读取SOAP内容,ruby-on-rails,soap,wsdl,savon,Ruby On Rails,Soap,Wsdl,Savon,我得到了一个wsdl的服务API,我从来没有这样做过,也不知道应该用它做什么 该文件描述了他们将向我们发送的内容: <?xml version="1.0" encoding="utf-8"?> <wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http
<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://moneysupermarket.com/callback" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" targetNamespace="http://moneysupermarket.com/callback" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="http://moneysupermarket.com/callback">
<s:element name="SendRequestCallBack">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="requestCallBack" type="tns:RequestCallBack" />
</s:sequence>
</s:complexType>
</s:element>
<s:complexType name="RequestCallBack">
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="QuoteId" type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="PhoneNumber" type="s:string" />
<s:element minOccurs="1" maxOccurs="1" name="CallTime" nillable="true" type="s:dateTime" />
</s:sequence>
</s:complexType>
</s:schema>
</wsdl:types>
<wsdl:message name="SendRequestCallBackSoapIn">
<wsdl:part name="parameters" element="tns:SendRequestCallBack" />
</wsdl:message>
<wsdl:portType name="ServiceSoap">
<wsdl:operation name="SendRequestCallBack">
<wsdl:input message="tns:SendRequestCallBackSoapIn" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="ServiceSoap" type="tns:ServiceSoap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="SendRequestCallBack">
<soap:operation soapAction="http://moneysupermarket.com/callback/SendRequestCallBack" style="document" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="ServiceSoap12" type="tns:ServiceSoap">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="SendRequestCallBack">
<soap12:operation soapAction="http://moneysupermarket.com/callback/SendRequestCallBack" style="document" />
<wsdl:input>
<soap12:body use="literal" />
</wsdl:input>
</wsdl:operation>
</wsdl:binding>
</wsdl:definitions>
到目前为止,我有以下代码不起作用:
class PhonebackRequest < ActiveRecord::Base
attr_reader :callTime, :phoneNumber, :quoteId
validates_presence_of :phoneNumber, :quoteId
def self.retrive_new_requests
# create a client for the service
client = Savon::Client.new File.path(Rails.public_path+"/moneysupermarket/Service.xml")
response = client.request(:wsdl, "send_request_call_back"){soap.body = { :requestCallBack => 'true' }}
#not sure what goes next
end
end
classphonebackrequest'true'}
#不知道接下来会发生什么
结束
结束
我通常只是通过打印#body
和#hash
的返回值来生成一个实现,以查看返回的类型值
下面给出了以下示例:
或者使用类似的方法查看响应正文中的确切数据结构。问题是,我们得到了结构xml文件,他们将向我们发送xml标志(我们没有请求)。因此,我们实际上并不是在请求,而是在等待他们请求我们(他们用xml文件描述他们的数据将是什么样子),我不确定我是否完全理解。您的应用程序正在接受来自其他客户端的请求?这不意味着您实际上正在创建服务器吗?如果是这样的话,那么客户机提供WSDL文件的部分就不太合适了。
response.body[:response][:success] #=> true
response.body[:response][:name] #=> "luke"