soap-lc 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/COPYING +1 -1
- data/README +3 -0
- data/examples/HelloService.wsdl +49 -0
- data/examples/StockQuote.wsdl +64 -0
- data/examples/mono/NumberService.asmx +29 -0
- data/examples/mono/README.txt +3 -0
- data/examples/mono/index.html +6 -0
- data/examples/t_000.rb +21 -0
- data/examples/t_001.rb +51 -0
- data/examples/t_002.rb +34 -0
- data/examples/t_00X.rb +18 -0
- data/examples/t_010.rb +43 -0
- data/lib/soap/lc.rb +12 -20
- data/lib/soap/lc/core_ext.rb +28 -0
- data/lib/soap/lc/request.rb +83 -24
- data/lib/soap/lc/response.rb +44 -6
- data/lib/soap/lc/version.rb +5 -0
- data/lib/soap/lc/wsdl.rb +7 -6
- data/lib/soap/lc/wsdl/binding.rb +11 -4
- data/lib/soap/lc/wsdl/message.rb +0 -2
- data/lib/soap/lc/xsd.rb +11 -437
- data/lib/soap/lc/xsd/complextype.rb +136 -0
- data/lib/soap/lc/xsd/convert.rb +107 -0
- data/lib/soap/lc/xsd/element.rb +167 -0
- data/lib/soap/lc/xsd/enumeration.rb +6 -0
- data/lib/soap/lc/xsd/restriction.rb +76 -0
- data/lib/soap/lc/xsd/sequence.rb +117 -0
- data/lib/soap/lc/xsd/simpletype.rb +83 -0
- metadata +23 -2
data/COPYING
CHANGED
data/README
CHANGED
@@ -15,6 +15,9 @@ SOAP Lite Client provides support for developing clients interfaces from WSDL fi
|
|
15
15
|
=== 0.0.1:
|
16
16
|
* Initial release. So...
|
17
17
|
|
18
|
+
=== TODO:
|
19
|
+
* Add MTOM support (see http://www.javapassion.com/handsonlabs/wsmtom/, http://mtom4ruby.blogspot.com/ and http://www.w3.org/TR/soap12-mtom/)
|
20
|
+
|
18
21
|
== SYNOPSIS:
|
19
22
|
|
20
23
|
require 'soap/lc'
|
@@ -0,0 +1,49 @@
|
|
1
|
+
<definitions name="HelloService"
|
2
|
+
targetNamespace="http://www.examples.com/wsdl/HelloService.wsdl"
|
3
|
+
xmlns="http://schemas.xmlsoap.org/wsdl/"
|
4
|
+
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
|
5
|
+
xmlns:tns="http://www.examples.com/wsdl/HelloService.wsdl"
|
6
|
+
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
7
|
+
|
8
|
+
<message name="SayHelloRequest">
|
9
|
+
<part name="firstName" type="xsd:string"/>
|
10
|
+
</message>
|
11
|
+
<message name="SayHelloResponse">
|
12
|
+
<part name="greeting" type="xsd:string"/>
|
13
|
+
</message>
|
14
|
+
|
15
|
+
<portType name="Hello_PortType">
|
16
|
+
<operation name="sayHello">
|
17
|
+
<input message="tns:SayHelloRequest"/>
|
18
|
+
<output message="tns:SayHelloResponse"/>
|
19
|
+
</operation>
|
20
|
+
</portType>
|
21
|
+
|
22
|
+
<binding name="Hello_Binding" type="tns:Hello_PortType">
|
23
|
+
<soap:binding style="rpc"
|
24
|
+
transport="http://schemas.xmlsoap.org/soap/http"/>
|
25
|
+
<operation name="sayHello">
|
26
|
+
<soap:operation soapAction="sayHello"/>
|
27
|
+
<input>
|
28
|
+
<soap:body
|
29
|
+
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
|
30
|
+
namespace="urn:examples:helloservice"
|
31
|
+
use="encoded"/>
|
32
|
+
</input>
|
33
|
+
<output>
|
34
|
+
<soap:body
|
35
|
+
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
|
36
|
+
namespace="urn:examples:helloservice"
|
37
|
+
use="encoded"/>
|
38
|
+
</output>
|
39
|
+
</operation>
|
40
|
+
</binding>
|
41
|
+
|
42
|
+
<service name="Hello_Service">
|
43
|
+
<documentation>WSDL File for HelloService</documentation>
|
44
|
+
<port binding="tns:Hello_Binding" name="Hello_Port">
|
45
|
+
<soap:address
|
46
|
+
location="http://www.examples.com/SayHello/">
|
47
|
+
</port>
|
48
|
+
</service>
|
49
|
+
</definitions>
|
@@ -0,0 +1,64 @@
|
|
1
|
+
<?xml version="1.0"?>
|
2
|
+
<definitions name="StockQuote"
|
3
|
+
targetNamespace="http://example.com/stockquote.wsdl"
|
4
|
+
xmlns:tns="http://example.com/stockquote.wsdl"
|
5
|
+
xmlns:xsd1="http://example.com/stockquote.xsd"
|
6
|
+
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
|
7
|
+
xmlns="http://schemas.xmlsoap.org/wsdl/">
|
8
|
+
|
9
|
+
<types>
|
10
|
+
<schema targetNamespace="http://example.com/stockquote.xsd"
|
11
|
+
xmlns="http://www.w3.org/2000/10/XMLSchema">
|
12
|
+
<element name="TradePriceRequest">
|
13
|
+
<complexType>
|
14
|
+
<all>
|
15
|
+
<element name="tickerSymbol" type="string"/>
|
16
|
+
</all>
|
17
|
+
</complexType>
|
18
|
+
</element>
|
19
|
+
<element name="TradePrice">
|
20
|
+
<complexType>
|
21
|
+
<all>
|
22
|
+
<element name="price" type="float"/>
|
23
|
+
</all>
|
24
|
+
</complexType>
|
25
|
+
</element>
|
26
|
+
</schema>
|
27
|
+
</types>
|
28
|
+
|
29
|
+
<message name="GetLastTradePriceInput">
|
30
|
+
<part name="body" element="xsd1:TradePriceRequest"/>
|
31
|
+
</message>
|
32
|
+
|
33
|
+
<message name="GetLastTradePriceOutput">
|
34
|
+
<part name="body" element="xsd1:TradePrice"/>
|
35
|
+
</message>
|
36
|
+
|
37
|
+
<portType name="StockQuotePortType">
|
38
|
+
<operation name="GetLastTradePrice">
|
39
|
+
<input message="tns:GetLastTradePriceInput"/>
|
40
|
+
<output message="tns:GetLastTradePriceOutput"/>
|
41
|
+
</operation>
|
42
|
+
</portType>
|
43
|
+
|
44
|
+
<binding name="StockQuoteSoapBinding" type="tns:StockQuotePortType">
|
45
|
+
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
|
46
|
+
<operation name="GetLastTradePrice">
|
47
|
+
<soap:operation soapAction="http://example.com/GetLastTradePrice"/>
|
48
|
+
<input>
|
49
|
+
<soap:body use="literal"/>
|
50
|
+
</input>
|
51
|
+
<output>
|
52
|
+
<soap:body use="literal"/>
|
53
|
+
</output>
|
54
|
+
</operation>
|
55
|
+
</binding>
|
56
|
+
|
57
|
+
<service name="StockQuoteService">
|
58
|
+
<documentation>My first service</documentation>
|
59
|
+
<port name="StockQuotePort" binding="tns:StockQuoteSoapBinding">
|
60
|
+
<soap:address location="http://example.com/stockquote"/>
|
61
|
+
</port>
|
62
|
+
</service>
|
63
|
+
|
64
|
+
</definitions>
|
@@ -0,0 +1,29 @@
|
|
1
|
+
<%@ WebService Language="C#" Class="MathService.MathService" %>
|
2
|
+
|
3
|
+
using System;
|
4
|
+
using System.Web.Services;
|
5
|
+
|
6
|
+
namespace MathService
|
7
|
+
{
|
8
|
+
[WebService (Namespace = "http://tempuri.org/NumberService")]
|
9
|
+
public class MathService : WebService
|
10
|
+
{
|
11
|
+
[WebMethod]
|
12
|
+
public int AddNumbers (int number1, int number2)
|
13
|
+
{
|
14
|
+
return number1 + number2;
|
15
|
+
}
|
16
|
+
|
17
|
+
[WebMethod]
|
18
|
+
public int SubtractNumbers (int number1, int number2)
|
19
|
+
{
|
20
|
+
return number1 - number2;
|
21
|
+
}
|
22
|
+
|
23
|
+
[WebMethod]
|
24
|
+
public string HelloWorld( )
|
25
|
+
{
|
26
|
+
return "Hello World!";
|
27
|
+
}
|
28
|
+
}
|
29
|
+
}
|
data/examples/t_000.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
$:.unshift( "../lib" )
|
2
|
+
require "soap/lc"
|
3
|
+
require 'pp'
|
4
|
+
|
5
|
+
#r = SOAP::LC["http://tux0.vidal.net:8080/merlin-service/services/PackService?wsdl"].searchByName( :name => "actos" )
|
6
|
+
#r.response
|
7
|
+
|
8
|
+
#puts "-------------------------"
|
9
|
+
#pp SOAP::LC["http://tux0.vidal.net:8080/merlin-service/services/IndicationService?wsdl"].searchByName( :name => "Cardiopathie" ).response.to_h
|
10
|
+
|
11
|
+
#puts "-------------------------"
|
12
|
+
#r = SOAP::LC["http://tux0.vidal.net:8080/merlin-service/services/PackService?wsdl"].searchRefundingRateByIndicationId( :packId => 31664, :indicationId => 4416 )
|
13
|
+
|
14
|
+
#puts r.envelope
|
15
|
+
|
16
|
+
#pp r.response.to_h
|
17
|
+
|
18
|
+
# puts "--------------------------------------------"
|
19
|
+
|
20
|
+
r = SOAP::LC["http://tux0.vidal.net:8080/merlin-service/services/InteractionService?wsdl"].getInteractionCouplesForProductIds( :int => [1524, 15070, 10852, 28417, 86585], :severity => "TAKE_INTO_ACCOUNT")
|
21
|
+
pp r.response.to_h
|
data/examples/t_001.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
$:.unshift( "../lib" )
|
2
|
+
require 'soap/lc'
|
3
|
+
require 'pp'
|
4
|
+
require 'base64'
|
5
|
+
|
6
|
+
wsdl = "http://www.guru4.net/articoli/javascript-soap-client/demo/webservicedemo.asmx?WSDL"
|
7
|
+
#wsdl = "http://soap-lc.rubyforge.org/this_file_does_not_exist.wsdl"
|
8
|
+
# wsdl = "toto.wsdl"
|
9
|
+
s = SOAP::LC.new( ).wsdl( wsdl ).call( "HelloWorld" )
|
10
|
+
puts s.uri
|
11
|
+
pp s.headers
|
12
|
+
puts s.envelope
|
13
|
+
|
14
|
+
puts "----------------"
|
15
|
+
|
16
|
+
r = s.result
|
17
|
+
# puts r.error
|
18
|
+
puts r.to_xml
|
19
|
+
|
20
|
+
puts "========================================="
|
21
|
+
|
22
|
+
e = '<SOAP-ENV:Envelope
|
23
|
+
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
|
24
|
+
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
|
25
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
26
|
+
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
27
|
+
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
|
28
|
+
<SOAP-ENV:Header/>
|
29
|
+
<SOAP-ENV:Body>
|
30
|
+
<HelloWorld xmlns="http://www.guru4.net/"/>
|
31
|
+
</SOAP-ENV:Body>
|
32
|
+
</SOAP-ENV:Envelope>'
|
33
|
+
|
34
|
+
e = '<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:gur="http://www.guru4.net/">
|
35
|
+
<soap:Header/>
|
36
|
+
<soap:Body>
|
37
|
+
<gur:HelloWorld/>
|
38
|
+
</soap:Body>
|
39
|
+
</soap:Envelope>'
|
40
|
+
|
41
|
+
s = SOAP::Request.request( e, wsdl, "SOAPAction" => "http://www.guru4.net/HelloWorld" )
|
42
|
+
puts s.uri
|
43
|
+
pp s.headers
|
44
|
+
puts s.envelope
|
45
|
+
|
46
|
+
puts "----------------"
|
47
|
+
|
48
|
+
r = s.result
|
49
|
+
puts r.to_xml
|
50
|
+
|
51
|
+
puts "========================================="
|
data/examples/t_002.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
$:.unshift( "../lib" )
|
2
|
+
require "soap/lc"
|
3
|
+
require 'pp'
|
4
|
+
|
5
|
+
wsdl = "http://localhost:8080/NumberService.asmx?wsdl"
|
6
|
+
|
7
|
+
r = SOAP::LC.wsdl( wsdl, "MathServiceSoap" ).call( "AddNumbers", :number1 => 4, :number2 => 7 )
|
8
|
+
|
9
|
+
puts r.response['AddNumbersResult']
|
10
|
+
|
11
|
+
# puts "----------------"
|
12
|
+
#
|
13
|
+
#
|
14
|
+
#
|
15
|
+
# e = '<SOAP-ENV:Envelope
|
16
|
+
# xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
|
17
|
+
# xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
|
18
|
+
# xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
19
|
+
# xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
20
|
+
# SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
|
21
|
+
# <SOAP-ENV:Header/>
|
22
|
+
# <SOAP-ENV:Body>
|
23
|
+
# <AddNumbers xmlns="http://tempuri.org/NumberService">
|
24
|
+
# <number1>4</number1>
|
25
|
+
# <number2>7</number2>
|
26
|
+
# </AddNumbers>
|
27
|
+
# </SOAP-ENV:Body>
|
28
|
+
# </SOAP-ENV:Envelope>'
|
29
|
+
# s = SOAP::Request.request( e, wsdl, "SOAPAction" => "http://tempuri.org/NumberService/AddNumbers" )
|
30
|
+
# puts s.uri
|
31
|
+
# pp s.headers
|
32
|
+
# puts s.envelope
|
33
|
+
#
|
34
|
+
# pp s.result.to_h
|
data/examples/t_00X.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
$:.unshift( "../lib" )
|
2
|
+
require 'soap/lc/request'
|
3
|
+
require 'pp'
|
4
|
+
|
5
|
+
e = %w(<SOAP-ENV:Envelope
|
6
|
+
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
|
7
|
+
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
|
8
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
9
|
+
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
10
|
+
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
|
11
|
+
<SOAP-ENV:Header/>
|
12
|
+
<SOAP-ENV:Body>
|
13
|
+
<HelloWorld xmlns="urn:MyWebService">
|
14
|
+
<from>Greg</from>
|
15
|
+
</HelloWorld>
|
16
|
+
</SOAP-ENV:Body>
|
17
|
+
</SOAP-ENV:Envelope>)
|
18
|
+
puts SOAP::Request.request( e, "http://localhost:3000/hello/wsdl", "SOAPAction" => "my.soap.action" ).envelope
|
data/examples/t_010.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
$:.unshift( "../lib" )
|
3
|
+
require 'soap/lc'
|
4
|
+
|
5
|
+
class XsltTest < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
@wsdl = "sample.wsdl"
|
8
|
+
@s = SOAP::LC.new( )
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_instance
|
12
|
+
assert_instance_of( SOAP::LC, @s )
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_wsdl_load
|
16
|
+
@w = @s.wsdl( @wsdl )
|
17
|
+
assert_instance_of( SOAP::WSDL, @w )
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_cant_open_file
|
21
|
+
assert_raise SOAP::LCError do
|
22
|
+
w = @s.wsdl( "this_file_does_not_exist.wsdl" )
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_cant_open_uri
|
27
|
+
assert_raise SOAP::LCError do
|
28
|
+
w = @s.wsdl( "http://localhost:9999/this_file_does_not_exist.wsdl" )
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_file_404
|
33
|
+
assert_raise SOAP::LCError do
|
34
|
+
w = @s.wsdl( "http://soap-lc.rubyforge.org/this_file_does_not_exist.wsdl" )
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_undefine_method
|
39
|
+
assert_raise NoMethodError do
|
40
|
+
@w.thisMethodDoesNotExist( )
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/soap/lc.rb
CHANGED
@@ -1,43 +1,35 @@
|
|
1
1
|
require 'soap/lc/wsdl'
|
2
2
|
|
3
|
-
class String
|
4
|
-
def nns
|
5
|
-
self.gsub( /^[^:]*:/, "" )
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
class Hash
|
10
|
-
def keys_to_sym!( )
|
11
|
-
self.each {|k, v|
|
12
|
-
self.delete(k)
|
13
|
-
self[k.to_sym] = v
|
14
|
-
}
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
3
|
module SOAP
|
19
4
|
class LC
|
20
5
|
# Create a new SOAP Lite Client
|
21
6
|
#
|
22
7
|
# s = WSDL::LC.new( )
|
23
8
|
# # => #<SOAP::LC:0xNNNNNN>
|
24
|
-
def initialize( )
|
9
|
+
def initialize( ) #:nodoc:
|
25
10
|
end
|
26
11
|
|
27
12
|
# Set the WSDL URL and return a SOAP::WSDL object
|
28
13
|
#
|
29
|
-
#
|
14
|
+
# Parameters :
|
15
|
+
# +uri+ : path to the WSDL
|
16
|
+
# +binding+ : binding name (optional)
|
17
|
+
#
|
18
|
+
# Example :
|
19
|
+
# s = WSDL::LC.wsdl( "http://my.wsdl.com", "HelloService" )
|
30
20
|
# # => #<SOAP::WSDL:0xNNNNNN>
|
31
|
-
def wsdl( uri )
|
32
|
-
return SOAP::WSDL.new( uri )
|
21
|
+
def self.wsdl( uri, binding = nil )
|
22
|
+
return SOAP::WSDL.new( uri, binding )
|
33
23
|
end
|
34
24
|
|
35
25
|
# Create a new SOAP Lite client and set the WSDL URL
|
36
26
|
# Return a SOAP::WSDL object.
|
37
27
|
#
|
28
|
+
# Use this if binding is non ambigous
|
29
|
+
#
|
38
30
|
# s = SOAP::LC["http://my.wsdl.com"]
|
39
31
|
def self.[]( uri )
|
40
|
-
|
32
|
+
SOAP::LC.wsdl( uri, nil )
|
41
33
|
end
|
42
34
|
end
|
43
35
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class String #:nodoc:
|
2
|
+
def nns
|
3
|
+
self.gsub( /^[^:]*:/, "" )
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
class Hash #:nodoc:
|
8
|
+
def keys_to_sym!( )
|
9
|
+
self.each {|k, v|
|
10
|
+
self.delete(k)
|
11
|
+
self[k.to_sym] = v
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
def kvTable( k, v )
|
16
|
+
self[k] = v
|
17
|
+
# if( self.keys.include?(k) )
|
18
|
+
# if self[k].class == Array
|
19
|
+
# self[k] << v
|
20
|
+
# else
|
21
|
+
# self[k] = [self[k], v]
|
22
|
+
# end
|
23
|
+
# else
|
24
|
+
# self[k] = v
|
25
|
+
# end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
data/lib/soap/lc/request.rb
CHANGED
@@ -1,12 +1,18 @@
|
|
1
|
+
require 'soap/lc/core_ext'
|
2
|
+
|
3
|
+
require 'soap/lc/xsd'
|
1
4
|
require 'soap/lc/response'
|
5
|
+
require 'soap/lc/version'
|
6
|
+
require 'soap/lc/error'
|
2
7
|
|
3
8
|
module SOAP
|
4
9
|
class Request
|
5
|
-
def initialize( wsdl ) #:nodoc:
|
10
|
+
def initialize( wsdl, binding ) #:nodoc:
|
6
11
|
@wsdl = wsdl
|
12
|
+
@binding = binding
|
7
13
|
@request = nil
|
8
14
|
end
|
9
|
-
|
15
|
+
|
10
16
|
# Call a method for the current Request and get a SOAP::Response
|
11
17
|
#
|
12
18
|
# Example:
|
@@ -17,8 +23,42 @@ module SOAP
|
|
17
23
|
def method_missing( id, *args )
|
18
24
|
call( id.id2name, args[0] )
|
19
25
|
end
|
20
|
-
|
21
|
-
#
|
26
|
+
|
27
|
+
# Create a new SOAP::Request with the given envelope, uri and headers
|
28
|
+
#
|
29
|
+
# Example:
|
30
|
+
# e = '<SOAP-ENV:Envelope
|
31
|
+
# xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
|
32
|
+
# xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
|
33
|
+
# xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
34
|
+
# xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
35
|
+
# SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
|
36
|
+
# <SOAP-ENV:Header/>
|
37
|
+
# <SOAP-ENV:Body>
|
38
|
+
# <HelloWorld xmlns="urn:MyWebService">
|
39
|
+
# <from>Greg</from>
|
40
|
+
# </HelloWorld>
|
41
|
+
# </SOAP-ENV:Body>
|
42
|
+
# </SOAP-ENV:Envelope>'
|
43
|
+
# r = SOAP::Request.request( e, "http://localhost:3000/hello/wsdl", "SOAPAction" => "my.soap.action" )
|
44
|
+
def self.request( envelope, uri, headers = {} )
|
45
|
+
r = new( nil, nil )
|
46
|
+
r.r( envelope, uri, headers )
|
47
|
+
return r
|
48
|
+
end
|
49
|
+
def r( envelope, uri, headers ) #:nodoc:
|
50
|
+
@request = {
|
51
|
+
:headers => make_header( envelope, headers ),
|
52
|
+
:envelope => envelope,
|
53
|
+
:uri => uri,
|
54
|
+
:wsdl => nil,
|
55
|
+
:response => nil,
|
56
|
+
:binding => @binding,
|
57
|
+
:method => nil
|
58
|
+
}
|
59
|
+
end
|
60
|
+
|
61
|
+
# Call a method for the current Request
|
22
62
|
#
|
23
63
|
# Example:
|
24
64
|
# wsdl = SOAP::LC.new( ).wsdl( "http://..." )
|
@@ -27,10 +67,17 @@ module SOAP
|
|
27
67
|
# # => #<SOAP::Response:0xNNNNNN>
|
28
68
|
def call( methodName, args )
|
29
69
|
args = (args || {}).keys_to_sym!
|
30
|
-
|
70
|
+
|
31
71
|
# Get Binding
|
32
|
-
binding = @wsdl.bindings.getBindingForOperationName( methodName )
|
33
|
-
|
72
|
+
binding = @wsdl.bindings.getBindingForOperationName( @binding, methodName )
|
73
|
+
if binding.size == 0
|
74
|
+
raise SOAP::LCNoMethodError, "Undefined method `#{methodName}'"
|
75
|
+
elsif binding.size > 1
|
76
|
+
raise SOAP::LCError, "Ambigous method name `#{methodName}', please, specify a binding name"
|
77
|
+
else
|
78
|
+
binding = binding[0]
|
79
|
+
@binding = binding.name
|
80
|
+
end
|
34
81
|
|
35
82
|
# Get Binding Operation
|
36
83
|
binding_operation = binding.operations[methodName]
|
@@ -41,11 +88,10 @@ module SOAP
|
|
41
88
|
|
42
89
|
# Get message for input operation
|
43
90
|
input_message = @wsdl.messages[portType_operation[:input][:message].nns]
|
44
|
-
|
91
|
+
|
45
92
|
# Create method
|
46
93
|
soap_method = "<#{methodName} xmlns=\"#{@wsdl.targetNamespace}\">\n"
|
47
94
|
input_message.parts.each do |_, attrs|
|
48
|
-
|
49
95
|
case attrs[:mode]
|
50
96
|
when :type
|
51
97
|
if SOAP::XSD::ANY_SIMPLE_TYPE.include?( attrs[attrs[:mode]].nns )
|
@@ -74,11 +120,11 @@ module SOAP
|
|
74
120
|
else
|
75
121
|
raise SOAL::LCWSDLError, "Malformated element `#{attrs[attrs[:mode]]}'"
|
76
122
|
end
|
77
|
-
|
123
|
+
|
78
124
|
## TODO ---------- USE element[:key]
|
79
125
|
else
|
80
126
|
raise SOAP::LCWSDLError, "Malformated part #{attrs[:name]}"
|
81
|
-
|
127
|
+
end
|
82
128
|
end
|
83
129
|
soap_method += "</#{methodName}>\n"
|
84
130
|
|
@@ -88,10 +134,7 @@ module SOAP
|
|
88
134
|
end
|
89
135
|
|
90
136
|
# Create headers
|
91
|
-
headers =
|
92
|
-
'Content-Type' => 'application/soap+xml; charset=utf-8',
|
93
|
-
'Content-Length' => "#{envelope.length}"
|
94
|
-
}
|
137
|
+
headers = Hash.new
|
95
138
|
# Add SOAPAction to headers (if exist)
|
96
139
|
action = begin
|
97
140
|
binding_operation[:soapAction]
|
@@ -99,44 +142,60 @@ module SOAP
|
|
99
142
|
nil
|
100
143
|
end
|
101
144
|
headers['SOAPAction'] = action unless action.nil? or action.length == 0
|
102
|
-
|
145
|
+
|
103
146
|
# Search URI
|
104
147
|
service_port = @wsdl.services.getServicePortForBindingName( binding.name )
|
105
148
|
address = service_port[:address]
|
106
|
-
|
149
|
+
|
107
150
|
# Complete request
|
108
151
|
@request = {
|
109
|
-
:headers => headers,
|
152
|
+
:headers => make_header( envelope, headers ),
|
110
153
|
:envelope => envelope,
|
111
154
|
:uri => address,
|
112
|
-
:
|
155
|
+
:wsdl => @wsdl,
|
156
|
+
:response => @wsdl.messages[portType_operation[:output][:message].nns].name,
|
157
|
+
:binding => @binding,
|
158
|
+
:method => methodName
|
113
159
|
}
|
114
160
|
|
115
161
|
return self
|
116
162
|
end
|
117
|
-
|
163
|
+
|
118
164
|
# Get the SOAP Body for the request
|
119
165
|
def soap_body( soap_method )
|
120
166
|
"<SOAP-ENV:Body>\n" + soap_method + "</SOAP-ENV:Body>\n"
|
121
167
|
end
|
122
|
-
|
168
|
+
|
123
169
|
# Send request to the server and get a response (SOAP::Response)
|
124
170
|
def response( )
|
125
171
|
return( SOAP::Response.new( @request ) )
|
126
172
|
end
|
127
173
|
alias_method :result, :response
|
128
|
-
|
174
|
+
|
129
175
|
# Get the SOAP Envelope for the request
|
130
176
|
def envelope( )
|
131
177
|
@request[:envelope] || nil
|
132
178
|
end
|
133
|
-
|
179
|
+
|
134
180
|
# Get request headers
|
135
181
|
def headers( )
|
136
182
|
@request[:headers] || nil
|
137
183
|
end
|
138
184
|
|
185
|
+
# Get request URI
|
186
|
+
def uri()
|
187
|
+
@request[:uri] || nil
|
188
|
+
end
|
189
|
+
|
139
190
|
private
|
191
|
+
def make_header( e, h = {} )
|
192
|
+
{
|
193
|
+
'User-Agent' => "SOAP::LC (#{SOAP::LC::VERSION}); Ruby (#{VERSION})",
|
194
|
+
'Content-Type' => 'text/xml', #'application/soap+xml; charset=utf-8',
|
195
|
+
'Content-Length' => "#{e.length}"
|
196
|
+
}.merge( h )
|
197
|
+
end
|
198
|
+
|
140
199
|
def soap_envelop( &b )
|
141
200
|
"<SOAP-ENV:Envelope
|
142
201
|
xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"
|
@@ -147,7 +206,7 @@ module SOAP
|
|
147
206
|
yield() +
|
148
207
|
'</SOAP-ENV:Envelope>'
|
149
208
|
end
|
150
|
-
|
209
|
+
|
151
210
|
def soap_header()
|
152
211
|
"<SOAP-ENV:Header/>\n"
|
153
212
|
end
|