2012-04-08 3 views
1

Savon을 사용하는이 코드를 사용했습니다.Savon SOAP 요청에서 네임 스페이스를 제거하십시오.

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 version="1.0" encoding="utf-8"?> 
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soap:Body> 
    <CreateMailing xmlns="https://www.cfhdocmail.com/LiveAutoAPI/"> 
     <Username>Username</Username> 
     <Password>Password</Password> 
     <ProductType>A4Letter</ProductType> 
     <IsMono/>true</IsMono> 
     <IsDuplex>true</IsDuplex> 
     <DespatchASAP>false</DespatchASAP> 
     <DespatchDate>2012-04-09 00:00:00 +0200</DespatchDate> 
     <AddressNameFormat>Full Name</AddressNameFormat> 
     <ReturnFormat>JSON</ReturnFormat> 
    </CreateMailing> 
    </soap:Body> 
</soap:Envelope> 

어떻게하면됩니까?

나는 순간에이 오류가 발생하고있어

Server did not recognize the value of HTTP Header SOAPAction: CreateMailing. (Savon::SOAP::Fault) 
+1

[this] (http://stackoverflow.com/a/6969379/89876)가 질문에 답변합니까? (특히 응답의'soap.input' 부분) – sluukkonen

답변

1

이러한 변경 사항은 내 문제를 해결했습니다.

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 

감사합니다. @sluukkonen에 도움을 요청합니다.

0

이 그것을 할 수있는 더 좋은 방법이 될 수 있지만 유일한 방법은 내가 필요한 방법 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 
관련 문제