WSDL. XSD. SOAP. Namespaces. Port types. If these terms make little sense, this presentation is for you. By the end of this presentation, you will completely understand how to dissect and decipher a web service interface, understand key design patterns, and learn how to develop top-down and bottom-up web services in technologies such as Java and Oracle SOA Suite. Want to know how to expose a PL/SQL package as a web service? This technical presentation, one of my most popular, is intended for DBAs and database developers who want to know what it takes to design and create web services.
Developing Web Services from Scratch - For DBAs and Database Developers
1. Raastech, Inc.
2201 Cooperative Way, Suite 600
Herndon, VA 20171
+1-703-884-2223
info@raastech.com
Developing Web Services from Scratch
For DBAs and Database Developers
BGOUG Spring 2017 Conference
Hotel RIU Pravets Resort
Saturday, June 3, 2017
16:00 - 17:00
Hall B
2. Š Raastech, Inc. 2017 | All rights reserved. Slide 2 of 61@Raastech
Agenda
1. Introduction
2. Introducing Web Services
3. Accessing a Web Service
4. Anatomy of a WSDL
5. Getting Started: Concepts
6. Live Development Demo
ī§ Java Web Service: Top-Down Development
ī§ Java Web Service: Bottom-Up Development
ī§ BPEL Web Service
7. Recap & Summary
4. Š Raastech, Inc. 2017 | All rights reserved. Slide 4 of 61@Raastech
About Me
ī§ Ahmed Aboulnaga @Ahmed_Aboulnaga
ī§ 18+ years Oracle experience
ī§ Author of âOracle SOA Suite 11g Administratorâs Handbookâ
ī§ Author of âOracle SOA Suite 12c Administratorâs Guideâ
ī§ OCE (SOA Foundation Practitioner)
ī§ Oracle ACE
5. Š Raastech, Inc. 2017 | All rights reserved. Slide 5 of 61@Raastech
About Raastech
ī§ Small systems integrator founded in 2009
ī§ Headquartered in the Washington DC area
ī§ Specializes in Oracle Fusion Middleware
ī§ Oracle Gold Partner
ī§ Oracle SOA Specialized
6. Š Raastech, Inc. 2017 | All rights reserved. Slide 6 of 61@Raastech
Why This Presentation
ī§ Learn to develop a web service from scratch
ī§ Lot of PL/SQL developers are intimidated by SOA development
ī§ Presentation is specific to SOAP, but concepts are similar for REST
8. Š Raastech, Inc. 2017 | All rights reserved. Slide 8 of 61@Raastech
ī§ How application access was previously developed
PL/SQL
ProcedurePL/SQL
Procedure
SQL
Developer
Java
Application
.NET
Application
ODBC driver
JDBC driver
SQL*NET
(internal)
Custom Drivers
9. Š Raastech, Inc. 2017 | All rights reserved. Slide 9 of 61@Raastech
ī§ ProC anyone?
ī§ Must be aware of the
technology of the target system
implementation and import the
necessary libraries and drivers
compatible with that technology
PL/SQL
ApplicationJava
Application
AS/400
Mainframe
.NET
Application
.NET drivers
IBM JARs
JDBC driver
Specific Target Implementation
10. Š Raastech, Inc. 2017 | All rights reserved. Slide 10 of 61@Raastech
ī§ Standardization on SOAP over HTTP
Web
ServiceAny
Application
Java
Application
.NET
Application
SOAP over HTTP
SOAP over HTTP
SOAP over HTTP
SOAP over HTTP
11. Š Raastech, Inc. 2017 | All rights reserved. Slide 11 of 61@Raastech
ī§ No need to worry about
implementation technology
of target applications
AWS
Java
Application
SalesForce
Paypal
SOAP over HTTP
SOAP over HTTP
SOAP over HTTP
Agnostic Target Implementation
12. Š Raastech, Inc. 2017 | All rights reserved. Slide 12 of 61@Raastech
CREATE PROCEDURE getWeather (
zipcode IN VARCHAR2,
temperature OUT NUMBER)
IS
BEGIN
temperature := '35';
END;
CREATE PROCEDURE setWeather (
zipcode IN VARCHAR2,
temperature IN NUMBER)
IS
BEGIN
INSERT INTO temperature
VALUES (zipcode, temperature);
END;
Request-Response
Synchronous
1-way
Asynchronous
PL/SQL Samples
13. Š Raastech, Inc. 2017 | All rights reserved. Slide 13 of 61@Raastech
PL/SQL
Procedure
PL/SQL
Procedure
PL/SQL
Procedure
PL/SQL
Procedure
Synchronous vs. Asynchronous
14. Š Raastech, Inc. 2017 | All rights reserved. Slide 14 of 61@Raastech
15. Š Raastech, Inc. 2017 | All rights reserved. Slide 15 of 61@Raastech
ī§ Now that business functionality is exposed as web services, these
services need to be consumed somehow.
ī§ Since web services are standards based, they can be invoked via the
majority of programming languages or through other services.
Web Service Clients
16. Š Raastech, Inc. 2017 | All rights reserved. Slide 16 of 61@Raastech
soapUI
17. Š Raastech, Inc. 2017 | All rights reserved. Slide 17 of 61@Raastech
ī§ The web service interface is accessible via an HTTP URL:
http://admin.raastech.com:7001/GetWeather/WeatherPort?WSDL
ī§ The web service implementation may or may not reside on the same
service:
<soap:address location="http://srv.raastech.com:8888/GetWeather/WeatherPort"/>
ī§ Often impossible to tell what underlying language was used to create
the web service.
Accessing a WSDL
18. Š Raastech, Inc. 2017 | All rights reserved. Slide 18 of 61@Raastech
19. Š Raastech, Inc. 2017 | All rights reserved. Slide 19 of 61@Raastech
<definitions name="Weather">
<types>
<schema>
<element name="zip" type="string"/>
<element name="temp" type="string"/>
</schema>
</types>
<message name="zipReq"><part name="parameters" element="zip"/></message>
<message name="tempResp"><part name="parameters" element="temp"/></message>
<portType name="WeatherPort">
<operation name="getWeather">
<input message="zipReq"/>
<output message="tempResp"/>
</operation>
</portType>
<binding name="WeatherBinding" type="WeatherPort">
<operation name="getWeather">
<input name="zipReq"/>
<output name="tempResp"/>
</operation>
</binding>
<service name="WeatherService">
<port name="WeatherPort" binding="WeatherBinding">
<soap:address location="http://localhost/wc/weather"/>
</port>
</service>
</definitions>
The WSDL is the
interface to the
web service.
Implementation
details of the web
service is unknown.
Dissecting a WSDL: Interface
20. Š Raastech, Inc. 2017 | All rights reserved. Slide 20 of 61@Raastech
<definitions name="Weather">
<types>
<schema>
<element name="zip" type="string"/>
<element name="temp" type="string"/>
</schema>
</types>
<message name="zipReq"><part name="parameters" element="zip"/></message>
<message name="tempResp"><part name="parameters" element="temp"/></message>
<portType name="WeatherPort">
<operation name="getWeather">
<input message="zipReq"/>
<output message="tempResp"/>
</operation>
</portType>
<binding name="WeatherBinding" type="WeatherPort">
<operation name="getWeather">
<input name="zipReq"/>
<output name="tempResp"/>
</operation>
</binding>
<service name="WeatherService">
<port name="WeatherPort" binding="WeatherBinding">
<soap:address location="http://localhost/wc/weather"/>
</port>
</service>
</definitions>
Location is referred
to as the âendpointâ.
Identifies where the
actual code resides.
Dissecting a WSDL: Endpoints
21. Š Raastech, Inc. 2017 | All rights reserved. Slide 21 of 61@Raastech
<definitions name="Weather">
<types>
<schema>
<element name="zip" type="string"/>
<element name="temp" type="string"/>
</schema>
</types>
<message name="zipReq"><part name="parameters" element="zip"/></message>
<message name="tempResp"><part name="parameters" element="temp"/></message>
<portType name="WeatherPort">
<operation name="getWeather">
<input message="zipReq"/>
<output message="tempResp"/>
</operation>
</portType>
<binding name="WeatherBinding" type="WeatherPort">
<operation name="getWeather">
<input name="zipReq"/>
<output name="tempResp"/>
</operation>
</binding>
<service name="WeatherService">
<port name="WeatherPort" binding="WeatherBinding">
<soap:address location="http://localhost/wc/weather"/>
</port>
</service>
</definitions>
This web service
has a single
operation, with an
input and an output
(i.e., synchronous).
Dissecting a WSDL: Operations
22. Š Raastech, Inc. 2017 | All rights reserved. Slide 22 of 61@Raastech
<definitions name="Weather">
<types>
<schema>
<element name="zip" type="string"/>
<element name="temp" type="string"/>
</schema>
</types>
<message name="zipReq"><part name="parameters" element="zip"/></message>
<message name="tempResp"><part name="parameters" element="temp"/></message>
<portType name="WeatherPort">
<operation name="getWeather">
<input message="zipReq"/>
<output message="tempResp"/>
</operation>
</portType>
<binding name="WeatherBinding" type="WeatherPort">
<operation name="getWeather">
<input name="zipReq"/>
<output name="tempResp"/>
</operation>
</binding>
<service name="WeatherService">
<port name="WeatherPort" binding="WeatherBinding">
<soap:address location="http://localhost/wc/weather"/>
</port>
</service>
</definitions>
The type of the
message is defined
in the âschemaâ.
Dissecting a WSDL: Messages
23. Š Raastech, Inc. 2017 | All rights reserved. Slide 23 of 61@Raastech
JavaBPEL
getCustomerSoapUI
getCustomerSoapUI
Todayâs Live Development Demo
24. Š Raastech, Inc. 2017 | All rights reserved. Slide 24 of 61@Raastech
25. Š Raastech, Inc. 2017 | All rights reserved. Slide 25 of 61@Raastech
ī§ http://www.w3schools.com/xml/default.asp
ī§ http://www.w3schools.com/schema/default.asp
ī§ http://www.w3schools.com/xpath/default.asp
ī§ http://www.w3schools.com/xsl/default.asp
ī§ http://www.w3schools.com/xquery/default.asp
ī§ http://www.w3schools.com/webservices/default.asp
ī§ http://www.w3schools.com/webservices/ws_wsdl_intro.asp
ī§ http://www.w3schools.com/webservices/ws_soap_intro.asp
ī§ http://blog.raastech.com/2009/01/creating-top-down-java-web-service-for.html
ī§ http://blog.raastech.com/2009/03/creating-bottom-up-java-web-service-for.html
w3schools References
26. Š Raastech, Inc. 2017 | All rights reserved. Slide 26 of 61@Raastech
ī§ XML stands for âEXtensible Markup Languageâ.
ī§ XML was designed to transport and store data.
ī§ XML is designed to be self-descriptive.
ī§ XML was originally designed to transport and store data.
ī§ XML does not contain any logic.
Introduction to XML
27. Š Raastech, Inc. 2017 | All rights reserved. Slide 27 of 61@Raastech
ī§ XML documents follow a tree structure.
ī§ Every XML document must have 1 root element.
ī§ The root element is the parent of all other elements.
<Customer>
<Name>John Doe</Name>
<OrderNumber>61237</OrderNumber>
<Items>
<Item quantity="2">Book</Item>
</Items>
</Customer>
XML Structure â Root Element
28. Š Raastech, Inc. 2017 | All rights reserved. Slide 28 of 61@Raastech
ī§ Comments
<Customer>
<!-- this is a comment -->
<Name>John Doe</Name>
<OrderNumber>61237</OrderNumber>
<Items>
<Item quantity="2">Book</Item>
</Items>
</Customer>
XML Structure â Comments
29. Š Raastech, Inc. 2017 | All rights reserved. Slide 29 of 61@Raastech
ī§ XML documents must have open and close tags.
ī§ Valid HTML, but invalid XML:
<li> XML is easy
XML Structure â Tags
30. Š Raastech, Inc. 2017 | All rights reserved. Slide 30 of 61@Raastech
ī§ Open and close tags must have matching case
ī§ Valid HTML, but invalid XML:
<Customer>John Doe</customer>
XML Structure â Tags
31. Š Raastech, Inc. 2017 | All rights reserved. Slide 31 of 61@Raastech
ī§ XML elements must be properly nested
ī§ Valid HTML, but invalid XML:
<b><u>Hello World</b><u>
XML Structure â Tags
32. Š Raastech, Inc. 2017 | All rights reserved. Slide 32 of 61@Raastech
ī§ Entity reference.
< < less than
> > greater than
& & ampersand
' ' apostrophe
" " quotation mark
XML Structure â Entity Reference
33. Š Raastech, Inc. 2017 | All rights reserved. Slide 33 of 61@Raastech
ī§ Unlike HTML, whitespace is preserved in XML.
<Customer>
<Name>John Doe
is a person. His age is 20.</Name>
</Customer>
XML Structure â Whitespace
34. Š Raastech, Inc. 2017 | All rights reserved. Slide 34 of 61@Raastech
ī§ Attributes
<Customer OrderNumber="61237">
<Items>
<Item quantity="2">Book</Item>
<Item quantity="1">Binder</Item>
</Items>
</Customer>
XML Structure â Attributes
35. Š Raastech, Inc. 2017 | All rights reserved. Slide 35 of 61@Raastech
ī§ Should you use elements or attributes when designing XML
documents?
<Customer>
<OrderNumber>61237</OrderNumber>
<Items>
<Item quantity="1">Binder</Item>
</Items>
</Customer>
<Customer OrderNumber="61237">
<Items>
<Item quantity="1">Binder</Item>
</Items>
</Customer>
XML Structure â Attributes vs. Elements
36. Š Raastech, Inc. 2017 | All rights reserved. Slide 36 of 61@Raastech
ī§ Namespaces are identifiers.
<Customers>
<e:Customer xmlns:e="http://raastech.com/Employees">
<e:Name>John Doe</e:Name>
</e:Customer>
<p:Customer xmlns:p="http://raastech.com/Partners">
<p:Name>Jane Doe</p:Name>
</p:Customer>
<Customers>
XML Structure â Namespaces
37. Š Raastech, Inc. 2017 | All rights reserved. Slide 37 of 61@Raastech
ī§ Default namespace; no need to prefix all child elements.
<Customer xmlns="http://raastech.com/Employees">
<Name>John Doe</Name>
</Customer>
XML Structure â Default Namespace
38. Š Raastech, Inc. 2017 | All rights reserved. Slide 38 of 61@Raastech
ī§ XML Schema defines elements in an XML document.
ī§ XML Schema defines attributes in an XML document.
ī§ XML Schema defines child elements, and optionally their number
and order.
ī§ XML Schema defines data types for both elements and attributes.
ī§ XML Schema defines default and fixed values for elements and
attributes.
Introduction to XML Schema
39. Š Raastech, Inc. 2017 | All rights reserved. Slide 39 of 61@Raastech
ī§ XML Schemas are well-formed XML documents and are extensible.
ī§ They are typically saved as .xsd files.
ī§ The root element of every XML Schema is the <schema> element.
ī§ The <schema> element may include attributes such as the XML
namespace.
Introduction to XML Schema
40. Š Raastech, Inc. 2017 | All rights reserved. Slide 40 of 61@Raastech
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:element name="Customer">
<xs:complexType>
<xs:sequence>
<xs:element name="OrderNumber" type="xs:string"/>
<xs:element name="Name" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Example of an XML Schema
41. Š Raastech, Inc. 2017 | All rights reserved. Slide 41 of 61@Raastech
ī§ A simple element contains only plain text that can be defined in one
of several predefined data types (or custom types).
ī§ The predefined data types in XML Schema include:
ī§ string
ī§ decimal
ī§ integer
ī§ boolean
ī§ date
ī§ time
Simple Element
42. Š Raastech, Inc. 2017 | All rights reserved. Slide 42 of 61@Raastech
ī§ String
<someelement>Hello World</someelement>
ī§ Decimal
<someelement>12.50</someelement>
ī§ Integer
<someelement>12</someelement>
ī§ Boolean
<someelement>true</someelement>
Data Types
43. Š Raastech, Inc. 2017 | All rights reserved. Slide 43 of 61@Raastech
ī§ Date
<someelement>2002-09-24Z</someelement>
<someelement>2008-07-24-06:00</someelement>
ī§ Time
<someelement>08:00:00</someelement>
ī§ DateTime
<someelement>2008-07-24T08:00:00</someelement>
Data Types
44. Š Raastech, Inc. 2017 | All rights reserved. Slide 44 of 61@Raastech
ī§ Restrictions are also referred to as facets.
ī§ Examples include:
ī§ minInclusive
ī§ maxInclusive
ī§ Enumeration
ī§ fractionDigits
ī§ Length
ī§ maxInclusive
ī§ maxExclusive
ī§ maxLength
ī§ minLength
ī§ totalDigits
Restrictions
45. Š Raastech, Inc. 2017 | All rights reserved. Slide 45 of 61@Raastech
ī§ Complex elements are XML elements that contains other elements
or attributes.
<xs:element name="Customer">
<xs:complexType>
<xs:sequence>
<xs:element name="Name" type="xs:string"/>
<xs:element name="Item" type="xs:ItemType" minOccurs="1" maxOccurs="5"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="ItemType">
<xs:sequence>
<xs:element name="Item" type="xs:string"/>
<xs:element name="Price" type="xs:decimal"/>
</xs:sequence>
</xs:complexType>
Complex Element
46. Š Raastech, Inc. 2017 | All rights reserved. Slide 46 of 61@Raastech
ī§ SOAP stands for Simple Object Access Protocol.
ī§ It is a communication protocol and allows XML documents to be
exchange over HTTP.
ī§ As a result, it is platform and technology independent, and ideal for
Internet-based communication.
ī§ A SOAP message is an XML document that contains the following:
ī§ Envelope
ī§ Header
ī§ Body
ī§ Fault
Introduction to SOAP
47. Š Raastech, Inc. 2017 | All rights reserved. Slide 47 of 61@Raastech
ī§ Envelope
ī§ Root element of a SOAP message.
ī§ xmlns:soap namespace should always have the value of
http://www.w3.org/2001/12/soap-envelope.
ī§ Header
ī§ Optional.
ī§ Could include information such as authentication information.
ī§ First child element of the Envelope element.
ī§ Body
ī§ Required.
ī§ Contains the content of the SOAP message (i.e., the payload).
SOAP Message
48. Š Raastech, Inc. 2017 | All rights reserved. Slide 48 of 61@Raastech
ī§ Example:
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope">
<soap:Header>
</soap:Header>
<soap:Body>
<m:Customer xmlns:m="http://raastech.com/Customer">
<m:Name>John Doe</m:Name>
</m:Customer>
</soap:Body>
</soap:Envelope>
SOAP Message
49. Š Raastech, Inc. 2017 | All rights reserved. Slide 49 of 61@Raastech
ī§ WSDL stands for Web Services Description Language.
ī§ It is an XML document that describes a web service (i.e., it is the
interface specification for the web service).
ī§ It specifies the location of the web service, the operations it
supports, and the message types.
Introduction to WSDL
50. Š Raastech, Inc. 2017 | All rights reserved. Slide 50 of 61@Raastech
51. Š Raastech, Inc. 2017 | All rights reserved. Slide 51 of 61@Raastech
ī§ A top-down web service begins with a WSDL.
ī§ Stubs for the underlying Java classes are created.
ī§ Live Development Demo
Java Web Service Development: Top-Down
WSDL
(interface)
Java
(Class)
WSDL
(interface)
Create interface first Java class stub auto-created
Webservice
development
(top-down)
52. Š Raastech, Inc. 2017 | All rights reserved. Slide 52 of 61@Raastech
53. Š Raastech, Inc. 2017 | All rights reserved. Slide 53 of 61@Raastech
ī§ A bottom-up web service begins with an already existing Java class.
ī§ Class and methods are easily exposed as a web service interface.
ī§ Live Development Demo
Java Web Service Development: Bottom-Up
Java
(class)
WSDL
(interface)
Java
(class)
WSDL auto-generated
from Java class
Create Java class first
Webservice
development
(bottom-up)
54. Š Raastech, Inc. 2017 | All rights reserved. Slide 54 of 61@Raastech
55. Š Raastech, Inc. 2017 | All rights reserved. Slide 55 of 61@Raastech
ī§ Live Development Demo
BPEL Web Service Development
56. Š Raastech, Inc. 2017 | All rights reserved. Slide 56 of 61@Raastech
57. Š Raastech, Inc. 2017 | All rights reserved. Slide 57 of 61@Raastech
{
"Customer":
{
"FirstName":"John",
"LastName":"Doe"
}
}
<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope">
<soap:Body>
<m:Customer xmlns:m="http://raastech.com/Customer">
<m:FirstName>John</m:FirstName>
<m:LastName>Doe</m:LastName>
</m:Customer>
</soap:Body>
SOAP/XML Message
ī§ Strong message type validation
ī§ Based on XML standard
ī§ Wide usage and adoption
ī§ Not size-friendly:
ī§ Size of data: 7 bytes
ī§ Size of message: 236 bytes
REST/JSON Message
ī§ Lightweight and efficient (mobile!)
ī§ Growing usage and adoption
ī§ Most moving to REST now
ī§ Size-friendly:
ī§ Size of data: 7 bytes
ī§ Size of message: 50 bytes
SOAP vs. REST
58. Š Raastech, Inc. 2017 | All rights reserved. Slide 58 of 61@Raastech
ī§ http://www.ateam-oracle.com/performance-study-rest-vs-soap-for-mobile-applications/
SOAP vs. REST
59. Š Raastech, Inc. 2017 | All rights reserved. Slide 59 of 61@Raastech
ī§ Why has web services become the accepted standard?
ī§ Are you more familiar with XML terminology?
ī§ What is a popular SOAP client testing tool?
ī§ What are the components of a SOAP message?
ī§ Can you understand a WSDL when you look at it now?
ī§ What is the difference between top-down and bottom-up web service
development?
ī§ What is REST?
Recap
60. Š Raastech, Inc. 2017 | All rights reserved. Slide 60 of 61@Raastech
Contact Information
ī§ Ahmed Aboulnaga
ī§ Technical Director
ī§ @Ahmed_Aboulnaga
ī§ ahmed.aboulnaga@raastech.com
61. Š Raastech, Inc. 2017 | All rights reserved. Slide 61 of 61@Raastech
Q&A