0

我得到了一个 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://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
4

1 回答 1

0

#body我通常只是通过打印and的返回值来查看一个实现以查看返回的类型值#hash

给定Savon 文档中的示例:

response.body[:response][:success] #=> true
response.body[:response][:name]    #=> "luke"

或者使用awesome_print之类的东西来查看响应正文中的确切数据结构。

于 2013-05-20T12:27:35.793 回答