如何使用 Savon gem 构建对 https://wyszukiwarkaregontest.stat.gov.pl 的正确 SOAP 请求
How build proper SOAP request to https://wyszukiwarkaregontest.stat.gov.pl with Savon gem
我正在尝试使用 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
时 returns:
"<?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 发出了请求,没有任何问题,但是有了这个……我花了几个小时来解决它,但一无所获。
谁能帮我? :)
好的,这是我的问题的解决方案:
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")
希望对您有用:)
我正在尝试使用 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
时 returns:
"<?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 发出了请求,没有任何问题,但是有了这个……我花了几个小时来解决它,但一无所获。 谁能帮我? :)
好的,这是我的问题的解决方案:
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")
希望对您有用:)