我正在尝试使用savon 2.7.2 gem来发出SOAP请求,如下所示:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:ns="http://CIS/BIR/PUBL/2014/07">
<soap:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
<wsa:Action>http://CIS/BIR/PUBL/2014/07/IUslugaBIRzewnPubl/Zaloguj</wsa:Action>
<wsa:To>https://wyszukiwarkaregontest.stat.gov.pl/wsBIR/UslugaBIRzewnPubl.svc</wsa:To>
</soap:Header>
<soap:Body>
<ns:Zaloguj>
<!--Optional:-->
<ns:pKluczUzytkownika>abcde12345abcde12345</ns:pKluczUzytkownika>
</ns:Zaloguj>
</soap:Body>
</soap:Envelope>
我尝试了不同的方法来实现这一目标,例如:
client = Savon.client(wsdl: "https://wyszukiwarkaregontest.stat.gov.pl/wsBIR/wsdl/UslugaBIRzewnPubl.xsd", namespace: "http://CIS/BIR/PUBL/2014/07")
client.call(:zaloguj, message: { "pKluczUzytkownika" => "abcde12345abcde12345" })
但它给了我Savon::HTTPError: HTTP error (415): The server cannot service the request because the media type is unsupported
当我检查savon的builder.build_document
时,它会返回:
"<?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=\"http://CIS/BIR/PUBL/2014/07\" xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\">
<env:Body>
<wsdl:Zaloguj>
<pKluczUzytkownika>abcde12345abcde12345</pKluczUzytkownika>
</wsdl:Zaloguj>
</env:Body>
</env:Envelope>"
我向RailsCasts的wsdl提出了没有问题的请求,但是有了这个......我花了几个小时来搞清楚,什么都没有。 谁能帮我? :)
答案 0 :(得分:2)
client = Savon.client(wsdl: "https://wyszukiwarkaregontest.stat.gov.pl/wsBIR/wsdl/UslugaBIRzewnPubl.xsd", namespace: "http://CIS/BIR/PUBL/2014/07", env_namespace: :soap, use_wsa_headers: true, soap_version: 2, endpoint: "https://wyszukiwarkaregontest.stat.gov.pl/wsBIR/UslugaBIRzewnPubl.svc", namespace_identifier: :ns)
response = client.call(:zaloguj, message: { "ns:pKluczUzytkownika" => "abcde12345abcde12345" }, soap_action: "http://CIS/BIR/PUBL/2014/07/IUslugaBIRzewnPubl/Zaloguj")
我希望,你发现它很有用:)