Savon皂体问题
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Savon 基于这样的假设:大多数请求 (XML) 足够简单,可以抽象为哈希。在这个复杂的示例中,我建议使用两种替代方案:
您可以使用任何 Ruby 对象(不是哈希)来代替哈希,并响应
to_s
。因此,您可以使用to_s
方法创建一个对象(或对象的层次结构),通过类似 Builder 并将其传递给Savon::SOAP::XML#body=
。您还可以使用
Savon::SOAP::XML#xml
,它为给定块生成一个 Builder 实例,以“动态”构造 XML。希望有帮助!另外,请查看新的 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:
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 ato_s
method constructing the XML via something like Builder and pass it toSavon::SOAP::XML#body=
.You could also use
Savon::SOAP::XML#xml
, which yields a Builder instance to a given block to construct the XML "on the fly".Hope that helps! Also, please take a look at the new Savon Guide.