我正在尝试使用 Java SOAP 客户端调用 Ruby SOAP Web 服务。而且我无法获得此网址的响应:
http://localhost:8080/calculation?wsdl
(恐怕如果上面的端点 url 对于下面的 web 服务是错误的)
红宝石 SOAP WS:
require "soap/rpc/standaloneserver"
begin
class MyServer < SOAP::RPC::StandaloneServer
# Expose our services
def initialize(*args)
super
add_method(self, 'add', 'a', 'b')
add_method(self, 'div', 'a', 'b')
end
# Handler methods
def add(a, b)
return a + b
end
def div(a, b)
return a / b
end
end
server = MyServer.new("MyServer",
'urn:ruby:calculation', 'localhost', 8080)
trap('INT'){
server.shutdown
}
server.start
rescue => err
puts err.message
end
我收到的错误是:
in `success_content': unexpected response: #<HTTP::Message::Headers:0x00000004328c10 @http_version="1.1", @body_size=0, @chunked=false, @request_method="GET", @request_uri=#<URI::HTTP http://localhost:8080/calculation?wsdl>, @request_query=nil, @request_absolute_uri=nil, @status_code=405, @reason_phrase="Method Not Allowed ", @body_type=nil, @body_charset=nil, @body_date=nil, @body_encoding=#<Encoding:ISO-8859-1>, @is_request=false, @header_item=[["Allow", "POST"], ["Content-Type", "text/html; charset=ISO-8859-1"], ["Server", "WEBrick/1.3.1 (Ruby/2.2.5/2016-04-26)"], ["Date", "Wed, 10 Aug 2016 05:02:29 GMT"], ["Content-Length", "297"], ["Connection", "close"]], @dumped=false> (HTTPClient::BadResponseError)
端点 url 错误吗?我用 Rub Client 调用它并且它工作(diff url)。有没有办法使用 JAVA 客户端调用?
红宝石 SOAP 客户端:
#!/usr/bin/ruby
require 'soap/rpc/driver'
NAMESPACE = 'urn:ruby:calculation'
URL = 'http://localhost:8080/'
begin
driver = SOAP::RPC::Driver.new(URL, NAMESPACE)
# Add remote sevice methods
driver.add_method('add', 'a', 'b')
# Call remote service methods
puts driver.add(200, 130)
rescue => err
puts err.message
end