Web Services Tutorial
Tamara Kogan
tkogan@cincom.com
2
About this tutorial
• Purpose of this tutorial:
– provide an introduction to Web services technology
– display VW’s support of Web services technology
– explain the use of Web services tools available in VW
Introduction to Web Services
4
Web Services Technology
• What are Web services about?
• The Web Services Model
• Enabling Technologies
• SOAP messages
• Web Services Description Language
5
What are Web Services about
• Web Services
is a technology that allows applications to communicate
with each other in a platform- and programming
language-independent manner.
• A Web Service
is a software interface that describes a collection of
operations that can be accessed over the network
through standardized XML messaging. It uses protocols
based on the XML language to describe an operation to
execute or data to exchange with another Web service.
6
The Web Services Model
Find Publish
Bind
Services
<Header>
<Body>
HTTP HTTP
SOAP
Client
Service
Provider
Service Registry
UDDI
Services Description
WSDL
Services Description
WSDL
7
Enabling Technologies
S
E
C
U
R
I
T
YNetwork
HTTP, FTP, IIOP, email
XML-Based message
SOAP
Service description
WSDL
Service discovery and publication
UDDI
8
SOAP 1.1 Message
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"/>
<SOAP-ENV:Header>
<m:Transaction
SOAP-ENV:actor="http://schemas.xmlsoap.org/soap/actor/next"
SOAP-ENV:mustUnderstand="1">5
</m:Transaction>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<m:HoldingByAcquisitionNumber xmlns:m="Some-URI“>1234567
</m:HoldingByAcquisitionNumber>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
9
SOAP Message Transmission
SOAP node SOAP node
Original
Sender
Intermediary Ultimate
Receiver
SOAP node
Role: Next Role:
Ultimate
Receiver
<password
role=“…/next”
mustUnderstand=“true”>..
<transaction
mustUnderstand=“true”>..
<publish >…</publish>
Target
Default target
Always targeted at
</Header>
<Body>
<Header>
</Body>
SOAP 1.1 is using: actor
SOAP 1.2 is using: role
10
Soap 1.1 Message over HTTP
POST /LibrarySearch HTTP/1.1
Host: www.libraryserver.com
Content-Type: text/xml; charset="utf-8"
Content-Length: nnnn
SOAPAction: "Some-URI”
<SOAP-ENV:Envelope
<SOAP-ENV:Header>
…
</SOAP-ENV:Header>
</SOAP-ENV:Body>
….
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
11
SOAP Fault Message
HTTP/1.1 500 Internal Server Error
Content-Type: text/xml; charset="utf-8"
Content-Length: nnnn
<SOAP-ENV:Envelope.. >
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Server</faultcode>
<faultstring>Server Error</faultstring>
<detail>
<e:myfaultdetails xmlns:e="Some-URI">
<message>My application didn't work</message>
<errorcode>1001</errorcode>
</e:myfaultdetails>
</detail>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
12
WSDL Schema
service
binding
SOAP/HTTP/MIME
portType
port
operation
message
types
schema
Service location and binding
Package details based on
specific protocol
Operation input and output
parameters
Operation parameter types
Data types
part
13
Describing a service in WSDL
WSLDSrvcSearch
searchByExactTitle: aString includeAffiliatedLibraries: aBoolean
| coll |
coll := self
searchServices: ( self searchServicesInclusive: aBoolean )
onAspect: #searchTitles
withMatchString: aString.
^coll isEmpty
ifTrue: [LDExcHoldingNotFound]
ifFalse:
[“Collection of LDHoldingBooks”
coll ]
Service provider
Exception
Return type
Operation
Input Parameter
names
Input Parameters
types
14
Describing parameter types
WSLDSrvcSearch
searchByExactTitle: aString
includingAffiliatedLibraries: aBoolean
RPC style:
<message name="SearchByExactTitleSoapIn">
<part name="SearchByExactTitle" type=“xsd:string"/>
<part name="IncludeAffiliatedLibraries" type=“xsd:boolean"/>
</message>
<message name="SearchByExactTitleSoapOut">
<part name="return" type="ns:CollectionOfLDHoldingBook”/>
</message>
Document style:
<message name="SearchByExactTitleIncludeAffiliatedLibrariesSoapIn">
<part name=“parameter" element="ns:SearchByExactTitleIncludeAffiliatedLibraries"/>
</message>
<message name="SearchByExactTitleIncludeAffiliatedLibrariesSoapOut">
<part name="return" element="ns:SearchByExactTitleIncludeAffiliatedLibrariesResponse"/>
</message>
15
WSDL RPC and Document styles
• Document/literal
– Message has one or zero parts
– Part is resolved using an element
– The element is complex type in most cases
– Data is serialized according to a schema
• RPC/encoded
– The Soap body contains an element with the name of a remove
procedure
– Message can have zero or more parts
– Each part corresponds a remote procedure parameter
– Each part is resolved using type
– Data is serialized according to SOAP 1.1
16
Describing types
<wsdl:types>
<wsdl:schema targetNamespace=“urn:someURL”>
<complexType name="LDHoldingBook">
<sequence>
<element name="dueDate" type="xsd:date"/>
<element name="language" type="xsd:string"/>
….
</sequence>
</complexType>
….
</wsdl:schema>
</wsd:types>
<element
name="SearchByExactTitleIncludeAffiliatedLibraries">
<complexType>
<sequence>
<element name="searchByExactTitle" type=“xsd:string"/>
<element name="includeAffiliatedLibraries"
type="xsd:boolean"/>
</sequence>
</complexType>
</element>
Document style describing
parameter types
17
Describing interfaces
WSLDSrvcSearch
searchByExactTitle: aString
includingAffiliatedLibraries: aBoolean
<portType name="WSLDSrvcSearch">
<operation name="SearchByExactTitleIncludeAffiliatedLibraries">
<input message="ns:SearchByExactTitleSoapIn"/>
<output message="ns:SearchByExactTitleSoapOut"/>
</operation>
<operation …>
….
</operation>
…..
</portType>
18
Describing message transfer
<binding name="WSLDSrvcSearch"
type="ns:WSLDSrvcSearch">
<soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http/"/>
<operation name="SearchByExactTitleIncludeAffiliatedLibraries"
selector="searchByExactTitle:includeAffiliatedLibraries:">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal" namespace="urn:Librarydoc"/>
</input>
<output>
<soap:body use="literal" namespace="urn:Librarydoc"/>
</output>
<fault name=“LDExcHoldingNotFound“.. />
</operation>
</binding>
Transport SOAP
over HTTP
VW specific, not
spec complaint
Not used by VW
Message
input/output wire
presentation
Exception
description
19
Describing service location
<service name=“LibraryServices">
<port name=“LibrarySearch" binding="ns: WSLDSrvcSearch ">
<soap:address location="http://localhost:3933/searchRpc"/>
</port>
</service> Access point for
SOAP binding
Can have one or more ports, each of which define a
connection method (for example, HTTP/SMTP, etc)
Web Services Support in VW
21
Web Services Frameworks
XML To Object Binding
WSDL
SOAP
UDDI
HTTP
Opentalk-XML
Opentalk-HTTP/CGI
Opentalk-SOAP
Client Server
22
Currently Supported Protocols
• SOAP 1.1
• Released SOAP 1.2 spec
• WSDL 1.1
• WSDL 1.2 spec work in progress
• UDDI v1
• Released UDDI v2 and v3 spec’s
23
VW Web Services Toolkit
• Provides support in
– creating XML to object binding from a schema
– marshaling/unmarshaling XML types in to Smalltalk object
and visa versa
– creating classes from XML to object binding
– building and deploying Web services from an existing
application
– creating classes from a WSDL schema and accessing Web
services
– searching and publishing Web services in UDDI registry
Web Services Invocation
25
Loading WSDL Schema
• WsdlBinding
– loads and register a WSDL schema
– creates Wsdl configuration
– serves as a repository of WSDL schemas
WsdlBinding
loadWsdlBindingFrom: self wsdlSpecification
readStream
26
How to access Web Services
• WsdlClient
– quick and easy way to invoke a service
– doesn’t create any classes
• WsdlClassBuilder
– create client classes to invoke a service
– can create Opentalk server and client and service
classes
• WsdlWizard
– GUI tool available in vw 73
27
WsdlClient
• Loads and parses a Wsdl schema
• Creates default binding to dictionaries
• Invokes a Web services
client := WsdlClient
url: ‘http://www.xmethods.net/sd/2001/CurrencyExchangeService.wsdl'.
rate := client
executeSelector: #getRate
args: (Array with: 'usa' with: ‘canada')
28
WsdlClassBuilder
• Loads and parses a Wsdl schema
• Creates XML to object binding and classes from it
• Creates client, server and service classes
builder := WsdlClassBuilder readFrom:
'http://www.xmethods.net/sd/2001/CurrencyExchangeService.wsdl' asURI.
builder package: 'CurrencyExchange'.
29
Creating WSDL Client Class
clientClass := builder createClientClasses first.
- derived from WsdlClient
- created for each WSDL port
Smalltalk defineClass: #CurrencyExchangePortClient
superclass: #{WebServices.WsdlClient}
#getRateCountry1: aString country2: aString1
#initialize
super initialize.
self setPortNamed: 'CurrencyExchangePort'.
#class wsdlSchema
"(WebServices.WsdlBinding loadWsdlBindingFrom:
self wsdlSchema readStream.)" …
WSDL schema with
XML to object binding
Port is registered in
WsdlPort.PortRegistry
30
Testing WSDL Client
client := clientClass new.
client createScript inspect.
rate := client
getRateCountry1: ‘usa’
country2: ‘canada’
31
Creating Service Class Stub
serviceClass := builder createServiceClasses first.
Smalltalk defineClass: #CurrencyExchangeBinding
superclass: #{Core.Object}
getRateCountry1: aString country2: aString1
<operationName: #getRate >
<addParameter: #country1 type: #String >
<addParameter: #country2 type: #String >
<result: #Float >
^self "Add implementation here"
32
Creating Opentalk Client
clientClass := builder createOpentalkClientClasses first.
Smalltalk defineClass: #OpentalkClientCurrencyExchangePort
superclass: #{Core.Object}
instanceVariableNames: 'client proxy ‘
#getRateCountry1: aString country2: aString1
^proxy getRateCountry1: aString country2: aString1
#serverUrl
^'http://services.xmethods.net:80/soap‘
#class wsdlSchema
"(WebServices.WsdlBinding
loadWsdlBindingFrom: self wsdlSchema readStream.)"
.
Request Broker
Remote Object
WSDL schema with XML
to Object Binding
33
Creating Opentalk Server
builder opentalkServerName: ‘ExchangeServer’.
serverClass := builder createOpentalkServerClass.
Smalltalk defineClass: #ExchangeServer
instanceVariableNames: 'interfaces servers ‘
#portDescription
<serviceClass: #CurrencyExchangeBinding
address: #'http://services.xmethods.net:80/soap'
bindingType: #soap
wsdlBinding: #CurrencyExchangeBinding >
<wsdlServiceImplementation: #CurrencyExchangeService >
^self
Request
Brokers
Corresponds
WSDL <port>
element
34
Testing locally
 Implement service method:
serviceClass>>getRateCountry1:country2:
^123
 Change server port to a local host:
serverClass class>>portDescription
<serviceClass: #'WebServices.LibraryServices' address:
#'http://localhost:4920' … >
 Set server access point for the client
clientClass>>serverUrl
^'http://localhost:4920'
35
Testing Opentalk Server and Client
client := clientClass new start.
[client
getRateCountry1: 'usa'
country2: ‘canada'
] ensure: [ client stop ]
server := serverClass new.
server startServers.
“Invoke client request”
server stopServers.
36
WsdlClassBuilder Settings
• Default package
– WSDefaultPackage
• Default proxy client port
– 4930
• Use existing classes or generate a new
uniquely named class
– yes
37
WSDL Wizard
Released in 7.3
38
Show Time Review
• Loaded a Wsdl schema
• Created XML to object binding
• Created classes from the binding
• Created a client for each port
• Created a script to invoke services
Building and Deploying
Web Services
40
Steps to build Web Services
• Provide services description
– Provide description to service interfaces
– Provide description to service parameters,
result and exception types
• Create a Wsdl schema
• Create Opentalk server
• Create Opentalk client
41
Classes to do the job
• WsdlBuilder
– expects service and types description
– creates a WSDL schema from a service class
• WsdlClassBuilder
– creates Opentalk server and client classes
• WSDLWizard
– helps to describe types
– creates Opentalk server and client classes
– tests client-server communication
– creates Wsdl schema
42
Service description
Should include:
– Operation name
– Parameter , result and exception types
WSLDSrvcGeneralPublic
holdingByAcquisitionNumber: anAcquisitionNumber
<operationName: #'HoldingByAcquisitionNumber'>
<addParameter: #‘acquisitionNumber' type: #'LargePositiveInteger'>
<result: #'LDHoldingBook'>
<addException: #NotFound type: #'LDExcHoldingNotFound'>
^library ownedHoldings
detect:[ :x | x acquisitionNumber = aLDHolding_acquisitionNumber ]
ifNone:[ LDExcHoldingNotFound raise]
43
Types description
Currently supported pragma types:
– Simple types
– Complex types
– Collections
– Choice
– Soap Array
– Struct
LDAgent
#borrowedHoldings: aCollOfLDHoldingBook
<addAttribute: #(#borrowedHoldings #optional)
type: #( #Collection #‘WebServices.LDHoldingBook' )>
borrowedHoldings := aCollOfLDHoldingBook
To be resolved should
be fully qualified
44
Creating a WSDL Schema
builder := WsdlBuilder
buildFromService: WSLDSrvcGeneralPublicDoc.
builder
setPortAddress: 'http://localhost:5050/srvcGeneralDoc'
forBindingNamed: ‘WSLDSrvcGeneralPublicDoc’
wsdlServiceNamed: 'LibraryDemoSoapDoc'.
stream := String new writeStream.
builder printSpecWithSmalltalkBindingOn: stream.
45
WsdlBuilder Settings
• Default target namespace
– the same target namespace is used for a WSDL schema definition
and types element
• Add the service super class methods
• Add selector attribute
• Style and use attributes
– Document/RPC encoded/literal
• Default service protocol
– the methods from this protocol are used to create Wsdl operations
• Default class namespace
– is used in XML to object binding to resolve types
46
WSDL Wizard
47
Show Time Review
• Described service parameters, result and
exception types
• Described data types
• Created Opentalk server
• Created Opentalk client
• Tested client server communication
• Created a Wsdl schema
48
Interoperability
• Document/literal schema style
– WS-I recommended
– Default in .NET
• Problem with RPC/encoded
• Inline type
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<item xsi:type="xsd:string">abc</item>
• Object identity
<inputStructArray href="#id3"/>
<struct SOAP-ENC:arrayType="ns1:SOAPStruct[3]" id="id3">
49
…Interoperability
• Support for XML “anyType”
<element name=“reference“/> - default type: “anyType”
– Simple types
– Complex types
• Support for nil attribute
– Schema description
<element name="varInt" type="long" nillable="true“/>
<element name="varInt" type="long"/> - nillable=“false“
– Message encoding
<varStruct xsi:nil="true"/>
50
Data Serialization Settings
• XMLObjectMarshalingManager
• #nillableDefault
• #useInlineType
• #useNilAttribute
• #useReference
• SoapArrayMarshaler
• #useEmptyLengthForDimension
<…SOAP-ENC:arrayType="xsd:string[]“../>
51
SOAP Header Support
• Wsdl client support in 7.2
– Add, marshal and unmarshal header entry
– No verification
• SOAP header processing model
– Preview for 7.3
– Opentalk client and server support
– Opentalk-SOAP-HeadersDemo package
52
SOAP Headers Processing
Model
Service Consumer Service Provider
Operation
Header
Processor
Operation
Header
Processor
Processing Policy
Header Entry Processors
… …
Header <Header>
Verifies,
unmarshals
<Header>
Header
Entries
Body
processing
53
Sending SOAP Headers
Opentalk.SOAPMarshaler defaultReturnedObject: #envelope.
client := Smalltalk.CustomerClient new.
client start.
(client headerFor: #AuthenticationToken)
value: ( AuthenticationToken new
userID: 'UserID';
password: 'password';
yourself).
envelope := client setCustomerID: 1234.
headerStruct := envelope header.
(headerStruct at: #Confirmation) value return = 'confirmed'
ifFalse: [ self error: 'wrong result'].
54
Opentalk Client Settings
There are a few options to set the Opentalk client result in
SOAPMarshaler defaultReturnedObject
– #result – returns the body value, default
– #envelope - returns instance of
WebServices.SoapEnvelope, having an envelope as a
result allows to get access to response header and body
– #response - returns a SoapResponse, the result can be
helpful for debugging purpose
55
Tutorial Wrap-up
• In this tutorial, we've done the following things:
– Learned about Web Services technology.
– Learned about how to describe an interface using
WSDL schema
– Reviewed VW Web Services Tool.
– Used the WS Tool to create Web service based systems
from WSDL files.
– Created and deployed a Web service system from an
existing application
– Learned about SOAP header processing model
56
Resources
• XML
– http://www.w3.org/TR/xmlschema-2/
• SOAP 1.1 specification
– http://www.w3.org/TR/soap/
• WSDL 1.1 specification
– http://www.w3.org/TR/wsdl.html
• UDDI specification
– http://www.oasis-open.org/committees/tc_home.php?wg_abbrev=
uddi-spec
• WS-I basic profile
– http://www.ws-i.org/Profiles/BasicProfile-1.0-2004-04-16.html
57

Web services tutorial

  • 1.
    Web Services Tutorial TamaraKogan tkogan@cincom.com
  • 2.
    2 About this tutorial •Purpose of this tutorial: – provide an introduction to Web services technology – display VW’s support of Web services technology – explain the use of Web services tools available in VW
  • 3.
  • 4.
    4 Web Services Technology •What are Web services about? • The Web Services Model • Enabling Technologies • SOAP messages • Web Services Description Language
  • 5.
    5 What are WebServices about • Web Services is a technology that allows applications to communicate with each other in a platform- and programming language-independent manner. • A Web Service is a software interface that describes a collection of operations that can be accessed over the network through standardized XML messaging. It uses protocols based on the XML language to describe an operation to execute or data to exchange with another Web service.
  • 6.
    6 The Web ServicesModel Find Publish Bind Services <Header> <Body> HTTP HTTP SOAP Client Service Provider Service Registry UDDI Services Description WSDL Services Description WSDL
  • 7.
    7 Enabling Technologies S E C U R I T YNetwork HTTP, FTP,IIOP, email XML-Based message SOAP Service description WSDL Service discovery and publication UDDI
  • 8.
  • 9.
    9 SOAP Message Transmission SOAPnode SOAP node Original Sender Intermediary Ultimate Receiver SOAP node Role: Next Role: Ultimate Receiver <password role=“…/next” mustUnderstand=“true”>.. <transaction mustUnderstand=“true”>.. <publish >…</publish> Target Default target Always targeted at </Header> <Body> <Header> </Body> SOAP 1.1 is using: actor SOAP 1.2 is using: role
  • 10.
    10 Soap 1.1 Messageover HTTP POST /LibrarySearch HTTP/1.1 Host: www.libraryserver.com Content-Type: text/xml; charset="utf-8" Content-Length: nnnn SOAPAction: "Some-URI” <SOAP-ENV:Envelope <SOAP-ENV:Header> … </SOAP-ENV:Header> </SOAP-ENV:Body> …. </SOAP-ENV:Body> </SOAP-ENV:Envelope>
  • 11.
    11 SOAP Fault Message HTTP/1.1500 Internal Server Error Content-Type: text/xml; charset="utf-8" Content-Length: nnnn <SOAP-ENV:Envelope.. > <SOAP-ENV:Body> <SOAP-ENV:Fault> <faultcode>SOAP-ENV:Server</faultcode> <faultstring>Server Error</faultstring> <detail> <e:myfaultdetails xmlns:e="Some-URI"> <message>My application didn't work</message> <errorcode>1001</errorcode> </e:myfaultdetails> </detail> </SOAP-ENV:Fault> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
  • 12.
    12 WSDL Schema service binding SOAP/HTTP/MIME portType port operation message types schema Service locationand binding Package details based on specific protocol Operation input and output parameters Operation parameter types Data types part
  • 13.
    13 Describing a servicein WSDL WSLDSrvcSearch searchByExactTitle: aString includeAffiliatedLibraries: aBoolean | coll | coll := self searchServices: ( self searchServicesInclusive: aBoolean ) onAspect: #searchTitles withMatchString: aString. ^coll isEmpty ifTrue: [LDExcHoldingNotFound] ifFalse: [“Collection of LDHoldingBooks” coll ] Service provider Exception Return type Operation Input Parameter names Input Parameters types
  • 14.
    14 Describing parameter types WSLDSrvcSearch searchByExactTitle:aString includingAffiliatedLibraries: aBoolean RPC style: <message name="SearchByExactTitleSoapIn"> <part name="SearchByExactTitle" type=“xsd:string"/> <part name="IncludeAffiliatedLibraries" type=“xsd:boolean"/> </message> <message name="SearchByExactTitleSoapOut"> <part name="return" type="ns:CollectionOfLDHoldingBook”/> </message> Document style: <message name="SearchByExactTitleIncludeAffiliatedLibrariesSoapIn"> <part name=“parameter" element="ns:SearchByExactTitleIncludeAffiliatedLibraries"/> </message> <message name="SearchByExactTitleIncludeAffiliatedLibrariesSoapOut"> <part name="return" element="ns:SearchByExactTitleIncludeAffiliatedLibrariesResponse"/> </message>
  • 15.
    15 WSDL RPC andDocument styles • Document/literal – Message has one or zero parts – Part is resolved using an element – The element is complex type in most cases – Data is serialized according to a schema • RPC/encoded – The Soap body contains an element with the name of a remove procedure – Message can have zero or more parts – Each part corresponds a remote procedure parameter – Each part is resolved using type – Data is serialized according to SOAP 1.1
  • 16.
    16 Describing types <wsdl:types> <wsdl:schema targetNamespace=“urn:someURL”> <complexTypename="LDHoldingBook"> <sequence> <element name="dueDate" type="xsd:date"/> <element name="language" type="xsd:string"/> …. </sequence> </complexType> …. </wsdl:schema> </wsd:types> <element name="SearchByExactTitleIncludeAffiliatedLibraries"> <complexType> <sequence> <element name="searchByExactTitle" type=“xsd:string"/> <element name="includeAffiliatedLibraries" type="xsd:boolean"/> </sequence> </complexType> </element> Document style describing parameter types
  • 17.
    17 Describing interfaces WSLDSrvcSearch searchByExactTitle: aString includingAffiliatedLibraries:aBoolean <portType name="WSLDSrvcSearch"> <operation name="SearchByExactTitleIncludeAffiliatedLibraries"> <input message="ns:SearchByExactTitleSoapIn"/> <output message="ns:SearchByExactTitleSoapOut"/> </operation> <operation …> …. </operation> ….. </portType>
  • 18.
    18 Describing message transfer <bindingname="WSLDSrvcSearch" type="ns:WSLDSrvcSearch"> <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http/"/> <operation name="SearchByExactTitleIncludeAffiliatedLibraries" selector="searchByExactTitle:includeAffiliatedLibraries:"> <soap:operation soapAction=""/> <input> <soap:body use="literal" namespace="urn:Librarydoc"/> </input> <output> <soap:body use="literal" namespace="urn:Librarydoc"/> </output> <fault name=“LDExcHoldingNotFound“.. /> </operation> </binding> Transport SOAP over HTTP VW specific, not spec complaint Not used by VW Message input/output wire presentation Exception description
  • 19.
    19 Describing service location <servicename=“LibraryServices"> <port name=“LibrarySearch" binding="ns: WSLDSrvcSearch "> <soap:address location="http://localhost:3933/searchRpc"/> </port> </service> Access point for SOAP binding Can have one or more ports, each of which define a connection method (for example, HTTP/SMTP, etc)
  • 20.
  • 21.
    21 Web Services Frameworks XMLTo Object Binding WSDL SOAP UDDI HTTP Opentalk-XML Opentalk-HTTP/CGI Opentalk-SOAP Client Server
  • 22.
    22 Currently Supported Protocols •SOAP 1.1 • Released SOAP 1.2 spec • WSDL 1.1 • WSDL 1.2 spec work in progress • UDDI v1 • Released UDDI v2 and v3 spec’s
  • 23.
    23 VW Web ServicesToolkit • Provides support in – creating XML to object binding from a schema – marshaling/unmarshaling XML types in to Smalltalk object and visa versa – creating classes from XML to object binding – building and deploying Web services from an existing application – creating classes from a WSDL schema and accessing Web services – searching and publishing Web services in UDDI registry
  • 24.
  • 25.
    25 Loading WSDL Schema •WsdlBinding – loads and register a WSDL schema – creates Wsdl configuration – serves as a repository of WSDL schemas WsdlBinding loadWsdlBindingFrom: self wsdlSpecification readStream
  • 26.
    26 How to accessWeb Services • WsdlClient – quick and easy way to invoke a service – doesn’t create any classes • WsdlClassBuilder – create client classes to invoke a service – can create Opentalk server and client and service classes • WsdlWizard – GUI tool available in vw 73
  • 27.
    27 WsdlClient • Loads andparses a Wsdl schema • Creates default binding to dictionaries • Invokes a Web services client := WsdlClient url: ‘http://www.xmethods.net/sd/2001/CurrencyExchangeService.wsdl'. rate := client executeSelector: #getRate args: (Array with: 'usa' with: ‘canada')
  • 28.
    28 WsdlClassBuilder • Loads andparses a Wsdl schema • Creates XML to object binding and classes from it • Creates client, server and service classes builder := WsdlClassBuilder readFrom: 'http://www.xmethods.net/sd/2001/CurrencyExchangeService.wsdl' asURI. builder package: 'CurrencyExchange'.
  • 29.
    29 Creating WSDL ClientClass clientClass := builder createClientClasses first. - derived from WsdlClient - created for each WSDL port Smalltalk defineClass: #CurrencyExchangePortClient superclass: #{WebServices.WsdlClient} #getRateCountry1: aString country2: aString1 #initialize super initialize. self setPortNamed: 'CurrencyExchangePort'. #class wsdlSchema "(WebServices.WsdlBinding loadWsdlBindingFrom: self wsdlSchema readStream.)" … WSDL schema with XML to object binding Port is registered in WsdlPort.PortRegistry
  • 30.
    30 Testing WSDL Client client:= clientClass new. client createScript inspect. rate := client getRateCountry1: ‘usa’ country2: ‘canada’
  • 31.
    31 Creating Service ClassStub serviceClass := builder createServiceClasses first. Smalltalk defineClass: #CurrencyExchangeBinding superclass: #{Core.Object} getRateCountry1: aString country2: aString1 <operationName: #getRate > <addParameter: #country1 type: #String > <addParameter: #country2 type: #String > <result: #Float > ^self "Add implementation here"
  • 32.
    32 Creating Opentalk Client clientClass:= builder createOpentalkClientClasses first. Smalltalk defineClass: #OpentalkClientCurrencyExchangePort superclass: #{Core.Object} instanceVariableNames: 'client proxy ‘ #getRateCountry1: aString country2: aString1 ^proxy getRateCountry1: aString country2: aString1 #serverUrl ^'http://services.xmethods.net:80/soap‘ #class wsdlSchema "(WebServices.WsdlBinding loadWsdlBindingFrom: self wsdlSchema readStream.)" . Request Broker Remote Object WSDL schema with XML to Object Binding
  • 33.
    33 Creating Opentalk Server builderopentalkServerName: ‘ExchangeServer’. serverClass := builder createOpentalkServerClass. Smalltalk defineClass: #ExchangeServer instanceVariableNames: 'interfaces servers ‘ #portDescription <serviceClass: #CurrencyExchangeBinding address: #'http://services.xmethods.net:80/soap' bindingType: #soap wsdlBinding: #CurrencyExchangeBinding > <wsdlServiceImplementation: #CurrencyExchangeService > ^self Request Brokers Corresponds WSDL <port> element
  • 34.
    34 Testing locally  Implementservice method: serviceClass>>getRateCountry1:country2: ^123  Change server port to a local host: serverClass class>>portDescription <serviceClass: #'WebServices.LibraryServices' address: #'http://localhost:4920' … >  Set server access point for the client clientClass>>serverUrl ^'http://localhost:4920'
  • 35.
    35 Testing Opentalk Serverand Client client := clientClass new start. [client getRateCountry1: 'usa' country2: ‘canada' ] ensure: [ client stop ] server := serverClass new. server startServers. “Invoke client request” server stopServers.
  • 36.
    36 WsdlClassBuilder Settings • Defaultpackage – WSDefaultPackage • Default proxy client port – 4930 • Use existing classes or generate a new uniquely named class – yes
  • 37.
  • 38.
    38 Show Time Review •Loaded a Wsdl schema • Created XML to object binding • Created classes from the binding • Created a client for each port • Created a script to invoke services
  • 39.
  • 40.
    40 Steps to buildWeb Services • Provide services description – Provide description to service interfaces – Provide description to service parameters, result and exception types • Create a Wsdl schema • Create Opentalk server • Create Opentalk client
  • 41.
    41 Classes to dothe job • WsdlBuilder – expects service and types description – creates a WSDL schema from a service class • WsdlClassBuilder – creates Opentalk server and client classes • WSDLWizard – helps to describe types – creates Opentalk server and client classes – tests client-server communication – creates Wsdl schema
  • 42.
    42 Service description Should include: –Operation name – Parameter , result and exception types WSLDSrvcGeneralPublic holdingByAcquisitionNumber: anAcquisitionNumber <operationName: #'HoldingByAcquisitionNumber'> <addParameter: #‘acquisitionNumber' type: #'LargePositiveInteger'> <result: #'LDHoldingBook'> <addException: #NotFound type: #'LDExcHoldingNotFound'> ^library ownedHoldings detect:[ :x | x acquisitionNumber = aLDHolding_acquisitionNumber ] ifNone:[ LDExcHoldingNotFound raise]
  • 43.
    43 Types description Currently supportedpragma types: – Simple types – Complex types – Collections – Choice – Soap Array – Struct LDAgent #borrowedHoldings: aCollOfLDHoldingBook <addAttribute: #(#borrowedHoldings #optional) type: #( #Collection #‘WebServices.LDHoldingBook' )> borrowedHoldings := aCollOfLDHoldingBook To be resolved should be fully qualified
  • 44.
    44 Creating a WSDLSchema builder := WsdlBuilder buildFromService: WSLDSrvcGeneralPublicDoc. builder setPortAddress: 'http://localhost:5050/srvcGeneralDoc' forBindingNamed: ‘WSLDSrvcGeneralPublicDoc’ wsdlServiceNamed: 'LibraryDemoSoapDoc'. stream := String new writeStream. builder printSpecWithSmalltalkBindingOn: stream.
  • 45.
    45 WsdlBuilder Settings • Defaulttarget namespace – the same target namespace is used for a WSDL schema definition and types element • Add the service super class methods • Add selector attribute • Style and use attributes – Document/RPC encoded/literal • Default service protocol – the methods from this protocol are used to create Wsdl operations • Default class namespace – is used in XML to object binding to resolve types
  • 46.
  • 47.
    47 Show Time Review •Described service parameters, result and exception types • Described data types • Created Opentalk server • Created Opentalk client • Tested client server communication • Created a Wsdl schema
  • 48.
    48 Interoperability • Document/literal schemastyle – WS-I recommended – Default in .NET • Problem with RPC/encoded • Inline type xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <item xsi:type="xsd:string">abc</item> • Object identity <inputStructArray href="#id3"/> <struct SOAP-ENC:arrayType="ns1:SOAPStruct[3]" id="id3">
  • 49.
    49 …Interoperability • Support forXML “anyType” <element name=“reference“/> - default type: “anyType” – Simple types – Complex types • Support for nil attribute – Schema description <element name="varInt" type="long" nillable="true“/> <element name="varInt" type="long"/> - nillable=“false“ – Message encoding <varStruct xsi:nil="true"/>
  • 50.
    50 Data Serialization Settings •XMLObjectMarshalingManager • #nillableDefault • #useInlineType • #useNilAttribute • #useReference • SoapArrayMarshaler • #useEmptyLengthForDimension <…SOAP-ENC:arrayType="xsd:string[]“../>
  • 51.
    51 SOAP Header Support •Wsdl client support in 7.2 – Add, marshal and unmarshal header entry – No verification • SOAP header processing model – Preview for 7.3 – Opentalk client and server support – Opentalk-SOAP-HeadersDemo package
  • 52.
    52 SOAP Headers Processing Model ServiceConsumer Service Provider Operation Header Processor Operation Header Processor Processing Policy Header Entry Processors … … Header <Header> Verifies, unmarshals <Header> Header Entries Body processing
  • 53.
    53 Sending SOAP Headers Opentalk.SOAPMarshalerdefaultReturnedObject: #envelope. client := Smalltalk.CustomerClient new. client start. (client headerFor: #AuthenticationToken) value: ( AuthenticationToken new userID: 'UserID'; password: 'password'; yourself). envelope := client setCustomerID: 1234. headerStruct := envelope header. (headerStruct at: #Confirmation) value return = 'confirmed' ifFalse: [ self error: 'wrong result'].
  • 54.
    54 Opentalk Client Settings Thereare a few options to set the Opentalk client result in SOAPMarshaler defaultReturnedObject – #result – returns the body value, default – #envelope - returns instance of WebServices.SoapEnvelope, having an envelope as a result allows to get access to response header and body – #response - returns a SoapResponse, the result can be helpful for debugging purpose
  • 55.
    55 Tutorial Wrap-up • Inthis tutorial, we've done the following things: – Learned about Web Services technology. – Learned about how to describe an interface using WSDL schema – Reviewed VW Web Services Tool. – Used the WS Tool to create Web service based systems from WSDL files. – Created and deployed a Web service system from an existing application – Learned about SOAP header processing model
  • 56.
    56 Resources • XML – http://www.w3.org/TR/xmlschema-2/ •SOAP 1.1 specification – http://www.w3.org/TR/soap/ • WSDL 1.1 specification – http://www.w3.org/TR/wsdl.html • UDDI specification – http://www.oasis-open.org/committees/tc_home.php?wg_abbrev= uddi-spec • WS-I basic profile – http://www.ws-i.org/Profiles/BasicProfile-1.0-2004-04-16.html
  • 57.