Ruby 从Savon SOAP请求中删除命名空间
我有这段代码,我正在努力使用它Ruby 从Savon SOAP请求中删除命名空间,ruby,xml,soap,savon,Ruby,Xml,Soap,Savon,我有这段代码,我正在努力使用它 require "savon" require "time" Gyoku.configure do |config| config.convert_symbols_to(&:tap) end client = Savon::Client.new("https://www.cfhdocmail.com/TestAPI2/DMWS.asmx?WSDL") response = client.request(:CreateMailing) do s
require "savon"
require "time"
Gyoku.configure do |config|
config.convert_symbols_to(&:tap)
end
client = Savon::Client.new("https://www.cfhdocmail.com/TestAPI2/DMWS.asmx?WSDL")
response = client.request(:CreateMailing) do
soap.body = {
Username: "Username",
Password: "Password",
ProductType: "A4Letter",
IsMono: false,
IsDuplex: true,
DespatchASAP: false,
DespatchDate: Time.parse("2012-04-09"),
AddressNameFormat: "Full Name",
ReturnFormat: "JSON"
}
end
输出如下所示
<?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:wsdl="https://www.cfhdocmail.com/LiveAutoAPI/" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ins0="https://www.cfhdocmail.com/LiveAutoAPI/">
<env:Body>
<ins0:CreateMailing>
<ins0:Username>Username</ins0:Username>
<ins0:Password>Password</ins0:Password>
<ins0:ProductType>A4Letter</ins0:ProductType>
<ins0:IsMono xsi:nil="true" />
<ins0:IsDuplex>true</ins0:IsDuplex>
<ins0:DespatchASAP xsi:nil="true" />
<ins0:DespatchDate>2012-04-09 00:00:00 +0200</ins0:DespatchDate>
<ins0:AddressNameFormat>Full Name</ins0:AddressNameFormat>
<ins0:ReturnFormat>JSON</ins0:ReturnFormat>
</ins0:CreateMailing>
</env:Body>
</env:Envelope>
也许有更好的方法可以做到这一点,但我唯一能弄清楚如何获得XML正文的方法就是构建自己的XML。我的模型中有一个to_xml方法,它的调用类似于
soap.body={to_xml}
def to_xml
xml = Builder::XmlMarkup.new(indent: 2)
xml.instruct!
xml.Username "Username"
xml.Password "Password"
end
这些改变解决了我的问题
client.request(:web, "CreateMailer") do |soap|
soap.input = [
"CreateMailer", {
xmlns: "https://www.cfhdocmail.com/LiveAutoAPI/"
}
]
soap.element_form_default = :unqualified
soap.body = {
Username: "Username",
Password: "Password",
ProductType: "A4Letter",
IsMono: false,
IsDuplex: true,
DespatchASAP: false,
DespatchDate: Time.parse("2012-04-09"),
AddressNameFormat: "Full Name",
ReturnFormat: "JSON"
}
client.http.headers.delete("SOAPAction")
end
谢谢你的帮助 回答你的问题了吗?(尤其是答案的soap.input
部分)
def to_xml
xml = Builder::XmlMarkup.new(indent: 2)
xml.instruct!
xml.Username "Username"
xml.Password "Password"
end
client.request(:web, "CreateMailer") do |soap|
soap.input = [
"CreateMailer", {
xmlns: "https://www.cfhdocmail.com/LiveAutoAPI/"
}
]
soap.element_form_default = :unqualified
soap.body = {
Username: "Username",
Password: "Password",
ProductType: "A4Letter",
IsMono: false,
IsDuplex: true,
DespatchASAP: false,
DespatchDate: Time.parse("2012-04-09"),
AddressNameFormat: "Full Name",
ReturnFormat: "JSON"
}
client.http.headers.delete("SOAPAction")
end