我正在使用Savon,它正在工作。我的WSDL是:
<definitions name="demo" targetNamespace="http://localhost:8090/demo">
<message name="DemoRequest">
<part name="param1" type="xsd:string"/>
</message>
<message name="DemoResponse">
<part name="Result" type="xsd:string"/>
</message>
<portType name="DemoPortType">
<operation name="Demo">
<input message="tns:DemoRequest"/>
<output message="tns:DemoResponse"/>
</operation>
</portType>
<binding name="DemoBinding" type="tns:DemoPortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="Demo">
<soap:operation soapAction="http://localhost:8090/Demo"/>
<input>
<soap:body use="encoded" namespace="http://localhost:8090/demo" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded" namespace="http://localhost:8090/demo" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>
<service name="DemoService">
<port name="DemoPort" binding="DemoBinding">
<soap:address location="http://localhost:8090/service.php"/>
</port>
</service>
</definitions>
我的Ruby程序是:
client=Savon.client(wsdl: "http://localhost:8090/demo.wsdl")
client.operations
=> [:demo]
client.call(:demo,message: {param1:"hola"}).body
=> {:demo_response=>{:result=>"Request received with param1 = hola"}}
我可以在没有Savon的情况下使用此功能吗?数据变量是从我正在使用Pro PHP Patterns Frameworks测试的指南中复制的,以及更多清单19-2第289页]
require 'net/https' require 'uri' require 'nokogiri' url = "http://localhost:8090/demo.wsdl" uri = URI.parse(url) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = false # Raw SOAP XML to be passed # TODO : Date should be dynamic data = <<-EOF <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> <ns1:Demo> <param1 xsi:type="xsd:string">abcdefg</param1> </ns1:Demo> </soap:Body> </soap:Envelope> EOF # # Set Headers # SOAPAction is mandatory headers = {'Content-Type' => 'text/xml; charset=utf-8','SOAPAction' => "http://localhost:8090/Demo"} result= http.post(uri.path, data, headers) # Parse doc = Nokogiri::XML(result.body) doc.remove_namespaces! # Remove namespaces from xml to make it clean p doc
变量
result
的结果是这样的:
{"date":["Mon, 27 Jan 2020 16:51:03 GMT"],"server":["Apache/2.4.41 (Unix) OpenSSL/1.1.1d PHP/7.4.1 mod_perl/2.0.8-dev Perl/v5.16.3"],"last-modified":["Sun, 26 Jan 2020 21:17:35 GMT"],"etag":["\"57c-59d118504f8aa\""],"accept-ranges":["bytes"],"content-length":["1404"],"connection":["close"]}
并且
result.body
变量是相同的wsdl文件,但没有任何响应
<?xml version ="1.0" encoding ="UTF-8" ?> <definitions name="demo" targetNamespace="http://localhost:8090/demo" xmlns:tns="http://localhost:8090/demo" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/"> <message name="DemoRequest"> <part name="param1" type="xsd:string" /> </message> <message name="DemoResponse"> <part name="Result" type="xsd:string" /> </message> <portType name="DemoPortType"> <operation name="Demo"> <input message="tns:DemoRequest" /> <output message="tns:DemoResponse" /> </operation> </portType> <binding name="DemoBinding" type="tns:DemoPortType"> <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" /> <operation name="Demo"> <soap:operation soapAction="http://localhost:8090/Demo" /> <input> <soap:body use="encoded" namespace="http://localhost:8090/demo" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" /> </input> <output> <soap:body use="encoded" namespace="http://localhost:8090/demo" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" /> </output> </operation> </binding> <service name="DemoService"> <port name="DemoPort" binding="DemoBinding"> <soap:address location="http://localhost:8090/service.php" /> </port> </service> </definitions>
我试图看到类似Savon的东西:
Request received with param1 = abcdefg"
但是没有用。
我正在使用Savon,它正在工作。我的WSDL是:
看起来像您的消息无效。
尝试发送此