Skip to content

Instantly share code, notes, and snippets.

@yhara
Created May 12, 2011 10:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yhara/968278 to your computer and use it in GitHub Desktop.
Save yhara/968278 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="UTF-8"?>
<definitions
name="CalcService"
targetNamespace="urn:CalcService"
xmlns:typens="urn:CalcService"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<!-- result = int AddIntegers(int a, int b) -->
<types>
</types>
<message name="AddIntegersRequest">
<part name="a" type="xsd:unsignedInt" />
<part name="b" type="xsd:unsignedInt" />
</message>
<message name="AddIntegersResponse">
<part name="result" type="xsd:unsignedInt" />
</message>
<portType name="CalcPortType">
<operation name="AddIntegers">
<input message="typens:AddIntegersRequest"/>
<output message="typens:AddIntegersResponse"/>
</operation>
</portType>
<binding name="CalcBinding" type="typens:CalcPortType">
<soap:binding style="rpc"
transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="AddIntegers">
<soap:operation soapAction="" />
<input name="AddIntegersRequest">
<soap:body use="encoded"
namespace="urn:CalcService"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output name="AddIntegersResponse">
<soap:body use="encoded"
namespace="urn:CalcService"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>
<service name="CalcServer">
<port name="CalcPortType" binding="typens:CalcBinding">
<soap:address location="http://localhost:10080/calc/service" />
</port>
</service>
</definitions>
#!/usr/bin/env ruby
require 'CalcServiceServant.rb'
require 'CalcServiceMappingRegistry.rb'
require 'soap/rpc/standaloneServer'
class CalcPortType
NsCalcService = "urn:CalcService"
Methods = [
[ XSD::QName.new(NsCalcService, "AddIntegers"),
"",
"addIntegers",
[ [:in, "a", ["::SOAP::SOAPUnsignedInt"]],
[:in, "b", ["::SOAP::SOAPUnsignedInt"]],
[:retval, "result", ["::SOAP::SOAPUnsignedInt"]] ],
{ :request_style => :rpc, :request_use => :encoded,
:response_style => :rpc, :response_use => :encoded,
:faults => {} }
]
]
end
class CalcPortTypeApp < ::SOAP::RPC::StandaloneServer
def initialize(*arg)
super(*arg)
servant = CalcPortType.new
CalcPortType::Methods.each do |definitions|
opt = definitions.last
if opt[:request_style] == :document
@router.add_document_operation(servant, *definitions)
else
@router.add_rpc_operation(servant, *definitions)
end
end
self.mapping_registry = CalcServiceMappingRegistry::EncodedRegistry
self.literal_mapping_registry = CalcServiceMappingRegistry::LiteralRegistry
end
end
if $0 == __FILE__
# Change listen port.
server = CalcPortTypeApp.new('app', nil, '0.0.0.0', 10080)
trap(:INT) do
server.shutdown
end
server.start
end
#!/usr/bin/env ruby
require 'CalcServiceDriver.rb'
endpoint_url = ARGV.shift
obj = CalcPortType.new(endpoint_url)
# run ruby with -d to see SOAP wiredumps.
obj.wiredump_dev = STDERR if $DEBUG
# SYNOPSIS
# addIntegers(a, b)
#
# ARGS
# a UnsignedInt - {http://www.w3.org/2001/XMLSchema}unsignedInt
# b UnsignedInt - {http://www.w3.org/2001/XMLSchema}unsignedInt
#
# RETURNS
# result UnsignedInt - {http://www.w3.org/2001/XMLSchema}unsignedInt
#
a = 1
b = 2
puts obj.addIntegers(a, b)
require 'xsd/qname'
require 'CalcService.rb'
require 'CalcServiceMappingRegistry.rb'
require 'soap/rpc/driver'
class CalcPortType < ::SOAP::RPC::Driver
DefaultEndpointUrl = "http://localhost:10080/calc/service"
NsCalcService = "urn:CalcService"
Methods = [
[ XSD::QName.new(NsCalcService, "AddIntegers"),
"",
"addIntegers",
[ [:in, "a", ["::SOAP::SOAPUnsignedInt"]],
[:in, "b", ["::SOAP::SOAPUnsignedInt"]],
[:retval, "result", ["::SOAP::SOAPUnsignedInt"]] ],
{ :request_style => :rpc, :request_use => :encoded,
:response_style => :rpc, :response_use => :encoded,
:faults => {} }
]
]
def initialize(endpoint_url = nil)
endpoint_url ||= DefaultEndpointUrl
super(endpoint_url, nil)
self.mapping_registry = CalcServiceMappingRegistry::EncodedRegistry
self.literal_mapping_registry = CalcServiceMappingRegistry::LiteralRegistry
init_methods
end
private
def init_methods
Methods.each do |definitions|
opt = definitions.last
if opt[:request_style] == :document
add_document_operation(*definitions)
else
add_rpc_operation(*definitions)
qname = definitions[0]
name = definitions[2]
if qname.name != name and qname.name.capitalize == name.capitalize
::SOAP::Mapping.define_singleton_method(self, qname.name) do |*arg|
__send__(name, *arg)
end
end
end
end
end
end
require 'CalcService.rb'
require 'soap/mapping'
module CalcServiceMappingRegistry
EncodedRegistry = ::SOAP::Mapping::EncodedRegistry.new
LiteralRegistry = ::SOAP::Mapping::LiteralRegistry.new
end
require 'CalcService.rb'
class CalcPortType
# SYNOPSIS
# addIntegers(a, b)
#
# ARGS
# a UnsignedInt - {http://www.w3.org/2001/XMLSchema}unsignedInt
# b UnsignedInt - {http://www.w3.org/2001/XMLSchema}unsignedInt
#
# RETURNS
# result UnsignedInt - {http://www.w3.org/2001/XMLSchema}unsignedInt
#
def addIntegers(a, b)
a+b
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment