Savon皂体问题

发布于 2024-11-14 20:16:53 字数 1729 浏览 3 评论 0原文

我正在使用 savon 0.9.2 和 ruby​​ 1.8.7。 我正在尝试提出复杂类型的肥皂请求。

我需要弄清楚如何使用 ruby​​ 和 savon 为以下类型的请求编写肥皂体。基本上,请求中的一个复杂类型扩展了另一种类型,并且也需要编码为数组。

肥皂请求对象应该看起来像这样。

<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:app="http://someurl/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
<soapenv:Header/>
<soapenv:Body>
<app:someMethod soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<xyzResReq xsi:type="java:xyzResReq" xmlns:java="java:com.xyz.request">
<somestring xsi:type="xsd:string">abc123</somestring>
<itinerary xsi:type="java1:xyzItinerary" xmlns:java1="java:com.xyz.domain">
<someList xsi:type="java2:List" soapenc:arrayType="xsd:anyType[]" xmlns:java2="java:language_builtins.util"/>
</itinerary>
</xyzResReq>
</app:someMethod>
</soapenv:Body>
</soapenv:Envelope> 

someList 又是模式形式中的复杂类型

<xsd:complexType name="someList">
<xsd:complexContent>
<xsd:extension base="stns:someBaseList">
<xsd:sequence>
<xsd:element maxOccurs="1" name="someElement" type="xsd:boolean" minOccurs="0" />
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>

,而 someBaseList 定义为

<xsd:complexType name="someBaseList"> 
<xsd:sequence>
<xsd:element maxOccurs="1" nillable="true" name="baseElement" type="xsd:string" minOccurs="0" />
</xsd:sequence>
</xsd:complexType>

How do I do this in savon.

I am using savon 0.9.2 and ruby 1.8.7.
I am trying to make a complex type soap request.

I need to figure out how to code the soap body for the below type of request using ruby and savon. Basically one of the complextypes in the request extends another type and also needs to be encoded as an array.

The soap request object is supposed to look like this.

<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:app="http://someurl/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
<soapenv:Header/>
<soapenv:Body>
<app:someMethod soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<xyzResReq xsi:type="java:xyzResReq" xmlns:java="java:com.xyz.request">
<somestring xsi:type="xsd:string">abc123</somestring>
<itinerary xsi:type="java1:xyzItinerary" xmlns:java1="java:com.xyz.domain">
<someList xsi:type="java2:List" soapenc:arrayType="xsd:anyType[]" xmlns:java2="java:language_builtins.util"/>
</itinerary>
</xyzResReq>
</app:someMethod>
</soapenv:Body>
</soapenv:Envelope> 

someList is again a complextype in the schema form

<xsd:complexType name="someList">
<xsd:complexContent>
<xsd:extension base="stns:someBaseList">
<xsd:sequence>
<xsd:element maxOccurs="1" name="someElement" type="xsd:boolean" minOccurs="0" />
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>

and someBaseList defined as

<xsd:complexType name="someBaseList"> 
<xsd:sequence>
<xsd:element maxOccurs="1" nillable="true" name="baseElement" type="xsd:string" minOccurs="0" />
</xsd:sequence>
</xsd:complexType>

How do I do this in savon.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤独难免 2024-11-21 20:16:53

Savon 基于这样的假设:大多数请求 (XML) 足够简单,可以抽象为哈希。在这个复杂的示例中,我建议使用两种替代方案:

  1. 您可以使用任何 Ruby 对象(不是哈希)来代替哈希,并响应 to_s。因此,您可以使用 to_s 方法创建一个对象(或对象的层次结构),通过类似 Builder 并将其传递给 Savon::SOAP::XML#body=

    类 SomeXML
      def self.to_s
        “<一些>xml”
      结尾
    结尾
    
    client.request :some_action 执行
      Soap.body = SomeXML
    结尾
    
  2. 您还可以使用 Savon::SOAP::XML#xml,它为给定块生成一个 Builder 实例,以“动态”构造 XML。

    client.request :some_action 执行
      Soap.xml 做 |xml|
        xml.person { |b| b.name(“吉姆”); b.电话(“555-1234”)}
      结尾
    结尾
    

希望有帮助!另外,请查看新的 Savon 指南

Savon is based on the assumption that most requests (XML) are simple enough to be abstracted as a Hash. In this complex example, I'd suggest two alternatives:

  1. Instead of a Hash, you can use any Ruby object (that's not a Hash) and responds to to_s. So you could create an object (or a hierarchy of objects) with a to_s method constructing the XML via something like Builder and pass it to Savon::SOAP::XML#body=.

    class SomeXML
      def self.to_s
        "<some>xml</some>"
      end
    end
    
    client.request :some_action do
      soap.body = SomeXML
    end
    
  2. You could also use Savon::SOAP::XML#xml, which yields a Builder instance to a given block to construct the XML "on the fly".

    client.request :some_action do
      soap.xml do |xml|
        xml.person { |b| b.name("Jim"); b.phone("555-1234") }
      end
    end
    

Hope that helps! Also, please take a look at the new Savon Guide.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文