This document provides a summary of a workshop on web services. It covers topics like XML, JSON, SOAP, REST, and security as they relate to building and consuming web services. The workshop objectives are to learn about XML, JSON, web services, SOAP, REST, security, testing services, and best practices. It includes hands-on exercises to work with XML, SOAP services, REST services, and JSON. Examples and concepts around namespaces, schemas, transformations, transactions, and service-oriented architecture are also presented.
2. Workshop Objectives
• During this workshop, you will learn
– XML
– JSON
– About Web services, SOA
• SOAP
• REST
– Security with Services
– Invoke and Testing web services
– Best Practices while dealing with Web services
3. System Setup
• SOAP UI
• Oxygen XML Editor
• Advanced Rest Client Plugin for Chrome
4. XML – Extensible Markup Language -1
• Designed to Describe Data
– Self Descriptive way representing the Data and Documents
• Platform agnostic Data representation for transferring data
• Easy to understand and follow
• Easy to convert to other formats
– HTML ,PDF , Word
5. XML – Example
<?xml version="1.0" encoding="UTF-8"?>
<StudentTranscript>
<ProgramName> Masters in Business Adminstration </ProgramName>
<Courses>
<Course>
<CourseCode>MBA/510</CourseCode>
<CourseCompletionDate> 8/8/1900</CourseCompletionDate>
<Credits>4</Credits>
<CourseGrade>A</CourseGrade>
</Course>
<Course>
<CourseCode>MBA/520</CourseCode>
<CourseCompletionDate> 8/8/1910</CourseCompletionDate>
<Credits>4</Credits>
<CourseGrade>B</CourseGrade>
</Course>
<Courses>
</StudentTranscript>
6. XML – Extensible Markup Language -2
• XML Document
– Elements
– Attributes
• Exactly one root element
– Parent of all the elements
– Forms a tree structure
• Start Tag and End Tag
– XML Tags are not predefined - Makeup your own tags
• CDATA – No Unescaped < or & characters in the data
• Well Formed XML
– All Elements need to have a closing tag
– XML tags are case-sensitive
– XML tags must be properly nested
– All attributes need to be enclosed in quotations
– Elements cannot have attributes of the same name
– Elements can be empty <studentTranscript/>
7. XML – Example
<?xml version="1.0" encoding="UTF-8"?>
<StudentTranscript>
<ProgramName> Masters in Business Adminstration </ProgramName>
<Courses>
<Course code=“MBA/510” completionDate=“8/8/1900” credits=“4”
grade=“A”/>
<Course code=“MBA/520” completionDate=“8/8/1920” credits=“4”
grade=“B”/>
<Courses>
</StudentTranscript>
What is the Difference ?
9. Namespace
• Element Name Conflicts
– What if same element name needs to be under different entities ?
• Trying to combine data from two different xmls
– Ex: description of a course and description of a program
• Use namespaces
– Similar to packages – separates the elements with unique prefixes.
10. Namespace
<Program>
<Name>MBA V1</Name>
<description>Master of Business Administration </description>
</Program>
<Course>
<Name>MBA/510</Name>
<description>Marketing 101</description>
</Course>
We would want to combine them or using it together is student transcription xml
<p:Program xmlns:p=“http://program”>
<p:Name>MBA V1</p:Name>
<p:description>Master of Business Administration </p:description>
</p:Program>
<c:Course xmlns:c=“http://course”>
<c:Name>MBA/510</c:Name>
<c:description>Marketing 101</c:description>
</c:Course>
11. XSLT and XML Schema
• XML Schema
– Describes the structure of an xml Document
• Supports data types
• Put restrictions on possible values
– Written in XML
– Validate that the XML is Valid
• Valid Vs Wellformed
• XSLT – extensible stylesheet language transformation
– Uses XPATH
– Outputs a file – another html,xml pdf …
12. Web service
• “Web Services are self-contained, modular, distributed, dynamic applications that can be described,
published, located, or invoked over the network to create products, processes, and supply chains. These
applications can be local, distributed, or Web-based. Web services are built on top of open standards such
as TCP/IP, HTTP, Java, HTML, and XML. “
• Services offered over the web ?
– A modular component that does a specific functionality
– The functionality is exposed out which can be invoked by other
services or applications.
– Input / Output is XML
• Ex: Profile Service ?
– Retrieves all the demographics data given a profile ID
– Ability to search for a student
– Ability to create a new profile for an user
– Ability to update address for an user
• How do we know what Input to be passed and what Output to
expect ?
13. Why use XML here?
• Can .NET invoke Java logic ?
• What is so unique about XML , that we have to use it here?
– Not tied to a specific programming language
– Any programming language that can parse XML can use the services
– Interoperability
• Transport Protocol
– HTTP, FTP,SMTP, JMS
14. SOAP - 1
• Simple Object Access Protocol
• XML based protocol for accessing web services
• Platform Independent
• Language Independent
• Extensible
• Transport Protocol
– HTTP , HTTPS, SMTP ..
15. SOAP - 2
• SOAP Payload is nothing but XML
• SOAP Payload
– Soap Envelope : Root Element
• SOAP Header
• SOAP Body
• SOAP Fault
• All elements are declared in default
namespace
17. SOAP Fault
• Inside SOAP Body
• Fault Code
– Code for Identifying the Fault
• Server
• Client
• Fault String
– Explanation of the Fault
• Detail
– Application Specific Error
18. SOAP Fault Example
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-
ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Client</faultcode>
<faultstring>Message does not have necessary info</faultstring>
<faultactor>http://gizmos.com/order</faultactor>
<detail>
<PO:order xmlns:PO="http://gizmos.com/orders/">
Quantity element does not have a value</PO:order>
<PO:confirmation xmlns:PO="http://gizmos.com/confirm">
Incomplete address: no zip code</PO:confirmation>
</detail>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
19. WSDL
• Web Services Description Language
• XML-based language for describing Web
services.
• How do we know what Input to be passed and
what Output to expect ?
– Input and Output for a web service are described
using a WSDL
• Can there be a SOAP Service without WSDL ?
21. Review HTTP
• Hyper Text Transfer Protocol
– Request Headers
– Request Body
• HTTP VERBs
– GET
– POST
– PUT
– DELETE
• HTTP Headers
– Content-type
– Accept
– Cookie
– Authorization
22. HTTP Response Codes
• 1xx Informational
– 100 - Continue
• 2xx Success
– 200 – OK
– 201 – Created
– 202 – Accepted
• 3xx Redirection
– 301 – Moved Permanently
– 302 - Found
– 307 - Temporary Redirect
• 4xx Client Error
– 400 – Bad Request
– 401 – Unauthorized
– 402 - Payment Required
– 403 – Forbidden
– 404 – Not Found
– 405 – Method Not Allowed
– 409 - Edit Conflict
• 5xx Server Error
– 500 Internal Server Error
– 502 Bad Gateway
23. What is REST ?
• Representational State Transfer
– Architectural Style for developing web services
– Based on Doctoral Thesis from Roy Fielding
– REST is not a Standard
• Rest web services communicate over HTTP
Services
– HTTP VERBS - GET , POST, PUT,DELETE
– Resources addressed through URI
– Media Types -
– Http Response Codes
•
24. Characteristics of REST
• Uniform Interface
• Client-Server Decoupling
• Stateless
• Cacheable
• Layered System
27. PUT,POST,DELETE
• POST – Submits information to the service for processing
– Should typically return the new or modified resource.
– http://localhost/student
• Payload is passed in body and Id is part of the payload
• PUT – Add a new resource at the request URL
– http://localhost/student/{id}
• Payload is passed in body
• DELETE – Removes the resource at the request URL
– http://locathost/student/{id}
• OPTIONS – Indicates which methods are supported
• HEAD – Returns meta information about the request URL
29. JSON Example
• {
"StudentTranscript":{
"ProgramName":"Masters in Business Adminstration",
"Courses":{
"Course":[
{
"CourseCode":"MBA/510",
"CourseCompletionDate":"8/8/1900",
"Credits":4,
"CourseGrade":"A"
},
{
"CourseCode":"" <MBA/520 "",
"CourseCompletionDate":"8/8/1910",
"Credits":4,
"CourseGrade":"B"
}
]
}
}
}
30. Hands-On Exercise 4
• Build a JSON file to represent Student Profile
Data
• Compare the XML file and JSON
• What is the difference ?
• What do you prefer ?
33. SOA
• Principle and Practices for designing shared , reusable ,
distributed services
– Loose Coupling
– Self Describing Interfaces
– Synchronous and Asynchronous
– Service Registry
– Quality of Service
– Service Aggregation and service orchestration
34. SAAS,PAAS,IAAS
• PLATFORM
– Thing of this LEGO blocks using which you can build any application
• Software As a Service
• Platform AS a Service
• Infrastructure As a Service
Editor's Notes
There is an xml
<Program>
<Name>MBA V1</Name>
<description>Master of Business Administration </description>
</Program>
<Course>
<Name>MBA/510</Name>
<description>Marketing 101</description>
</Course>
We would want to combine them or using it together is student transcription xml
<p:Program xmlns:p=“http://program”>
<p:Name>MBA V1</p:Name>
<p:description>Master of Business Administration </p:description>
</p:Program>
<c:Course xmlns:c=“http://course”>
<c:Name>MBA/510</c:Name>
<c:description>Marketing 101</c:description>
</c:Course>
Sample Schema
Oxygen show how to generate xml file from XSD
Sample XSL
http://www.w3schools.com/xml/xml_xsl.asp
Sample Schema
Oxygen show how to generate xml file from XSD
Sample XSL
http://www.w3schools.com/xml/xml_xsl.asp
Representational
Clients possess the information necessary to identify, modify, and/or delete a web resource.
State
All resource state information is stored on the client.
Transfer
Client state is passed from the client to the service through HTTP.
What is the difference between GET , POST for html page
What if you have document that might need to use same name under elements for example : description of a product or place
Sample Schema
Oxygen show how to generate xml file from XSD
Sample XSL
http://www.w3schools.com/xml/xml_xsl.asp