web service overview
DESCRIPTION
โดย อ.ประพจน์ สุขมานนท์TRANSCRIPT
![Page 1: Web service overview](https://reader031.vdocuments.pub/reader031/viewer/2022020206/54641920af795969338b47af/html5/thumbnails/1.jpg)
Web Service Overview
![Page 2: Web service overview](https://reader031.vdocuments.pub/reader031/viewer/2022020206/54641920af795969338b47af/html5/thumbnails/2.jpg)
Function
� Function คือ โปรแกรมยอ่ยชนิดหนึ�ง ซึ�งอาจจะมีการรับคา่มาจากโปรแกรมหลกัที�เรียกใช้ Function นั (นๆ จากนั (นจะมีการประมวลผลคําสั�งใน Function พร้อมกบัจะมีการคืนคา่กลบัไปที�โปรแกรมหลกัที�เรียกใช้งาน Function นั (นๆ
Function cal (number As Integer) Dim result As Integerresult = number ** 2return resultEnd Function
…Call function cal(2)
importing result.write result.…
Function
Main Program 1
…Call function cal(4)
importing result.write result.…
Main Program 2
![Page 3: Web service overview](https://reader031.vdocuments.pub/reader031/viewer/2022020206/54641920af795969338b47af/html5/thumbnails/3.jpg)
Web Application
3.Web Service
2.Dynamic
1.Static
![Page 4: Web service overview](https://reader031.vdocuments.pub/reader031/viewer/2022020206/54641920af795969338b47af/html5/thumbnails/4.jpg)
HTTP request
Web Application ยุคที& 1 : Static Web Page
Web Browser Web Server
http://www.prapoj.com/current.html
Web Pages
HTTP response
![Page 5: Web service overview](https://reader031.vdocuments.pub/reader031/viewer/2022020206/54641920af795969338b47af/html5/thumbnails/5.jpg)
HTTP response
Web Application ยุคที& 2 : Dynamic Web Page
Data
Web Server
Database
SQL Statement
http://www.prapoj.com/index.asp
Web Browser
.asp,.jsp,.php,.pl…
Web Pages
HTTP request
![Page 6: Web service overview](https://reader031.vdocuments.pub/reader031/viewer/2022020206/54641920af795969338b47af/html5/thumbnails/6.jpg)
Web Server
Web Application ยุคที& 3 : Web Service Technology
http://www.prapoj.com/index.aspx
Web Browser
.asp,.php,.pl,jsp… Web Service
Web Service
HTTP requestSOAP over HTTP request
HTTP response
SOAP over HTTP request
Web Server
Web Server
![Page 7: Web service overview](https://reader031.vdocuments.pub/reader031/viewer/2022020206/54641920af795969338b47af/html5/thumbnails/7.jpg)
Distributed Computing
![Page 8: Web service overview](https://reader031.vdocuments.pub/reader031/viewer/2022020206/54641920af795969338b47af/html5/thumbnails/8.jpg)
JavaWorld
Programming World!
MicrosoftWorld
![Page 9: Web service overview](https://reader031.vdocuments.pub/reader031/viewer/2022020206/54641920af795969338b47af/html5/thumbnails/9.jpg)
Distributed Computing
.dll
ASP
VBC#
.NET
C++
EJB
Java
Java
Java
Java Java
Java
![Page 10: Web service overview](https://reader031.vdocuments.pub/reader031/viewer/2022020206/54641920af795969338b47af/html5/thumbnails/10.jpg)
Web Service
.dll
ASP
VBC#
.NET
C++
EJB
Java
Java
Java
Java Java
Java
Web ServiceWeb Service
WSDLWSDL
![Page 11: Web service overview](https://reader031.vdocuments.pub/reader031/viewer/2022020206/54641920af795969338b47af/html5/thumbnails/11.jpg)
What is Web Service?
![Page 12: Web service overview](https://reader031.vdocuments.pub/reader031/viewer/2022020206/54641920af795969338b47af/html5/thumbnails/12.jpg)
Web Service?
� Application หรือโปรแกรม(หรือ Function)ซึ�งทําหน้าที�อยา่งใดอยา่งหนึ�งในลกัษณะให้บริการ(Service) โดยจะถกูเรียกใช้งานจาก Application หรือโปรแกรมอื�นๆผา่นทาง Web (Web Server โดยอาศยั SOAP Protocol) การให้บริการของ Web Service นั (น จะมีเอกสารที�อธิบายคณุสมบตัขิองบริการกํากบัไว้(WSDL) และมีการนําเสนอให้สาธารณชนรับทราบ(UDDI) ผู้ ใช้บริการจงึสามารถที�จะค้นหาบริการของ Web Service ตา่งๆได้โดยไมจ่ําเป็นต้องรู้ที�อยู่จริงของ Application หรือโปรแกรมที�ให้บริการ Web Service นั (นๆ
![Page 13: Web service overview](https://reader031.vdocuments.pub/reader031/viewer/2022020206/54641920af795969338b47af/html5/thumbnails/13.jpg)
Web Service Definition� Web services are the fundamental building blocks in the move to distributed
computing on the Internet� Open standards and the focus on communication and collaboration among
people and applications have created an environment where XML Web Service are becoming the platform for application Integration
� Applications are constructed using multiple XML Web Services from various sources that work together regardless of where they reside or how they were implemented
� One of the primary advantages of the XML Web Services architecture is that it allows programs written in different languages on different platforms to communicate with each other in a standards-based way
![Page 14: Web service overview](https://reader031.vdocuments.pub/reader031/viewer/2022020206/54641920af795969338b47af/html5/thumbnails/14.jpg)
Web Service Concept
Component
Web Service
1
WSDL
Web Server
3
2
WSDL
“Web Services are self-contained, self-describing modular applications that
can be published, discovered and invoked across the Web”
4 SOAP Request
SOAP Response
5
![Page 15: Web service overview](https://reader031.vdocuments.pub/reader031/viewer/2022020206/54641920af795969338b47af/html5/thumbnails/15.jpg)
� สร้าง Web Service โดยการพฒันาแบบ Manual หรือใช้เครื�องมือ (Tool) ในการ Generate เราจะได้เอกสาร WSDL บรรยายคณุลกัษณะของ Web Service นั (นๆ
� ทําการ Publish ในสว่นของ Web Service ไปที� UDDI เพื�อให้บคุคลทั�วไปสามารถค้นหา Web Service ที�เราพฒันาขึ (นมาได้
ขั :นตอนในการพัฒนา Web Service
![Page 16: Web service overview](https://reader031.vdocuments.pub/reader031/viewer/2022020206/54641920af795969338b47af/html5/thumbnails/16.jpg)
� ค้นหาบริการ Web Service ผา่น UDDI ซึ�งทําให้เราได้ข้อมลูเกี�ยวกบัประเภทบริการ ที�ตั (งของบริการ และเอกสาร WSDL บรรยายคณุลกัษณะของบริการนั (นๆ
� ตดิตอ่ขอใช้บริการ Web Service โดยใช้ SOAP Protocol (SOAP Request)ด้วยการเขียนโปรแกรมขึ (นมาเรียกใช้ Method ของ Web Service นั (นๆโดยอาศยัข้อมลูที�อยูใ่นเอกสาร WSDL
� ผู้ให้บริการสง่ผลลพัธ์กลบัมาในรูปของ XML(SOAP Response)
ขั :นตอนในการเรียกใช้ Web Service
![Page 17: Web service overview](https://reader031.vdocuments.pub/reader031/viewer/2022020206/54641920af795969338b47af/html5/thumbnails/17.jpg)
Standards Behind Web services
� Simple Object Access Protocol (SOAP) is based on XML and Hypertext Transport Protocol. It provides a way for applications —including those running on different operating systems — to communicate and work together through remote procedure calls implemented via HTTP
� Universal Description, Discovery and Integration (UDDI) describes how to publish and discover information about Web services applications. It is a Web-based directory where someone can search for particular Web services and what they do
![Page 18: Web service overview](https://reader031.vdocuments.pub/reader031/viewer/2022020206/54641920af795969338b47af/html5/thumbnails/18.jpg)
Standards Behind Web services� Web Services Description Language (WSDL), based on XML,
describes the kinds of software applications, or services, available on a particular network. Once someone develops a Web service, they can publish its description and link in a special UDDI repository. When someone wants to use the service, they request the WSDL file so they can determine its location, function calls and how to get to them. They use that information to construct a SOAP request to aserver
� eXtensible Markup Language is a streamlined version of Standard Generalized Markup Language, developed by the International Organization for Standardization to define the structures of different types of electronic documents. XML can be used to store any kind of structured language and encapsulate data so it can be shared between otherwise incompatible computer systems
![Page 19: Web service overview](https://reader031.vdocuments.pub/reader031/viewer/2022020206/54641920af795969338b47af/html5/thumbnails/19.jpg)
Web Service Components
Web Service = WSDL + UDDI + SOAP
UDDI Business Registry
Search
Consume
Publis
h
Web Service
WSDLSOAP
UDDI
![Page 20: Web service overview](https://reader031.vdocuments.pub/reader031/viewer/2022020206/54641920af795969338b47af/html5/thumbnails/20.jpg)
� Web Service Description Language เป็นภาษาที�ใช้อธิบายคณุลกัษณะของ Web Service และวิธีในการตดิตอ่กบั Web Service โดยใช้ไวยากรณ์ของภาษา XML
WSDL
![Page 21: Web service overview](https://reader031.vdocuments.pub/reader031/viewer/2022020206/54641920af795969338b47af/html5/thumbnails/21.jpg)
� WSDL can be used to describe several primary qualities of a Web Service message:� The address Location of WSDL
� The Web Service name
� The Operation(Function/Method) name
� The Input/Output parameters
� The type of data being sent between client and server during a Web Service message exchange
WSDL
1
2
3
4
5
![Page 22: Web service overview](https://reader031.vdocuments.pub/reader031/viewer/2022020206/54641920af795969338b47af/html5/thumbnails/22.jpg)
WSDL
� WSDL is used to describe Web Services, client and users of Web Services will use the service descriptions in WSDL to create client proxies that access the service of the provider
� The provider defines the operations, the binding, and the endpoints all in the WSDL document
![Page 23: Web service overview](https://reader031.vdocuments.pub/reader031/viewer/2022020206/54641920af795969338b47af/html5/thumbnails/23.jpg)
WSDL
� WSDL stands for Web Services Description Language.
� WSDL is a document written in XML. The document describes a Web service. It specifies the location of the service and the operations (or methods) the service exposes.
![Page 24: Web service overview](https://reader031.vdocuments.pub/reader031/viewer/2022020206/54641920af795969338b47af/html5/thumbnails/24.jpg)
WSDL
� The main structure of a WSDL document looks like this:
![Page 25: Web service overview](https://reader031.vdocuments.pub/reader031/viewer/2022020206/54641920af795969338b47af/html5/thumbnails/25.jpg)
WSDL Ports� The <portType> element is the most important WSDL
element. � It describes a web service, the operations that can be
performed, and the messages that are involved.� The <portType> element can be compared to a function
library (or a module, or a class) in a traditional programming language.
WSDL Messages� The <message> element defines the data elements of an
operation.
� Each message can consist of one or more parts. The parts can be compared to the parameters of a function call in a traditional programming language.
![Page 26: Web service overview](https://reader031.vdocuments.pub/reader031/viewer/2022020206/54641920af795969338b47af/html5/thumbnails/26.jpg)
portType and message Example
![Page 27: Web service overview](https://reader031.vdocuments.pub/reader031/viewer/2022020206/54641920af795969338b47af/html5/thumbnails/27.jpg)
WSDL Types� The <types> element defines the data type that are used by the
web service.
� For maximum platform neutrality, WSDL uses XML Schema syntax to define data types.
![Page 28: Web service overview](https://reader031.vdocuments.pub/reader031/viewer/2022020206/54641920af795969338b47af/html5/thumbnails/28.jpg)
� Universal Description, Discovery and Integration � http://www.ibm.com/services/uddi/testregistry/find
� http://uddi.microsoft.com/search.aspx
� http://uddi.sap.com
� http://www.xmethods.net/
� http://www.webservicex.net
UDDI
![Page 29: Web service overview](https://reader031.vdocuments.pub/reader031/viewer/2022020206/54641920af795969338b47af/html5/thumbnails/29.jpg)
UDDI Example : XMETHODS
![Page 30: Web service overview](https://reader031.vdocuments.pub/reader031/viewer/2022020206/54641920af795969338b47af/html5/thumbnails/30.jpg)
www.webservicex.net
![Page 31: Web service overview](https://reader031.vdocuments.pub/reader031/viewer/2022020206/54641920af795969338b47af/html5/thumbnails/31.jpg)
� Simple Object Access Protocol เป็น Protocol ที�ใช้ในการเข้าถงึ Object หรือ Component อยา่งง่ายๆ
� SOAP เป็น Protocol ที�อาศยัไวยากรณ์ของภาษา XML
SOAP
![Page 32: Web service overview](https://reader031.vdocuments.pub/reader031/viewer/2022020206/54641920af795969338b47af/html5/thumbnails/32.jpg)
SOAP
� SOAP supports distributed computing with XML by providing an effective mechanism for exchanging messages and accessing remote objects via XML
![Page 33: Web service overview](https://reader031.vdocuments.pub/reader031/viewer/2022020206/54641920af795969338b47af/html5/thumbnails/33.jpg)
SOAP Message ExampleSOAP Request
SOAP Response
![Page 34: Web service overview](https://reader031.vdocuments.pub/reader031/viewer/2022020206/54641920af795969338b47af/html5/thumbnails/34.jpg)
� VB component
� using SOAP toolkit 3.0 to Generate Web Service
� Call Web Service from any client (Programs) � Perl
� Java
Creating Web Service using Tool
![Page 35: Web service overview](https://reader031.vdocuments.pub/reader031/viewer/2022020206/54641920af795969338b47af/html5/thumbnails/35.jpg)
� VB component MyAddProj.vbp
� Generate component -> MyAdd.dll
Creating COM Component using VB
Public Function Add(ByVal Num1 as Integer,ByVal Num2 as Integer) As IntegerAdd = Num1 + Num2
End Function
Register component
![Page 36: Web service overview](https://reader031.vdocuments.pub/reader031/viewer/2022020206/54641920af795969338b47af/html5/thumbnails/36.jpg)
� Using SOAP Toolkit From Microsoft� Download at http://msdn.microsoft.com
� MyAdd.dll -> � plus2num.wsdl(WSDL file)
Generate Web Service from COM Component
![Page 37: Web service overview](https://reader031.vdocuments.pub/reader031/viewer/2022020206/54641920af795969338b47af/html5/thumbnails/37.jpg)
SOAP Toolkit 3.0 WSDL Generator
![Page 38: Web service overview](https://reader031.vdocuments.pub/reader031/viewer/2022020206/54641920af795969338b47af/html5/thumbnails/38.jpg)
<?xml version='1.0' encoding='UTF-8' ?>...
<message name='MyAdd.Add'><part name='Num1' type='xsd:short'/><part name='Num2' type='xsd:short'/>
</message><message name='MyAdd.AddResponse'>
<part name='Result' type='xsd:short'/></message>
...<operation name='Add' >...<service name=‘MyAddWS' >...<soap:address location='http://161.200.70.44/myaddws.asp' />
WSDL File (MyAddWS.wsdl)
Web Service name
Operation name
Web Service location
Input Parameter
Output Parameter
http://161.200.70.44/MyAddWS.wsdl
![Page 39: Web service overview](https://reader031.vdocuments.pub/reader031/viewer/2022020206/54641920af795969338b47af/html5/thumbnails/39.jpg)
#!c:\perl\bin\perl.exeuse SOAP::Lite;use CGI;$obj = new CGI;$a = $obj->param(number1);$b = $obj->param(number2);print "Content-type:text/html\n\n";$strWSDL = "http://161.200.70.44/myaddws.asp";
print "Result from SOAP Server:</h4>";print "Answer --> ";
print SOAP::Lite-> service($strWSDL) -> Add($a,$b);
Perl Client
![Page 40: Web service overview](https://reader031.vdocuments.pub/reader031/viewer/2022020206/54641920af795969338b47af/html5/thumbnails/40.jpg)
import java.io.*;import java.util.*;import java.net.*;import org.w3c.dom.*;import org.apache.soap.util.xml.*;import org.apache.soap.*;import org.apache.soap.encoding.*;import org.apache.soap.encoding.soapenc.*;import org.apache.soap.rpc.*;import org.apache.soap.transport.http.SOAPHTTPConnection;public class testSoapResponse {public static void main(String[] args) throws Exception {URL url = new URL ("http://161.200.70.44/myaddws.asp");SOAPMappingRegistry smr = new SOAPMappingRegistry ();StringDeserializer sd = new StringDeserializer ();smr.mapTypes (Constants.NS_URI_SOAP_ENC,
new QName ("", "Result"), null, null, sd);
Java Client
![Page 41: Web service overview](https://reader031.vdocuments.pub/reader031/viewer/2022020206/54641920af795969338b47af/html5/thumbnails/41.jpg)
call.setTargetObjectURI ("http://tempuri.org/message/");call.setMethodName("Add");call.setEncodingStyleURI ("http://schemas.xmlsoap.org/soap/encoding/");Vector params = new Vector();params.addElement(new Parameter("Num1", Double.class,num1, null));params.addElement(new Parameter("Num2", Double.class,num2, null));call.setParams(params);Response resp = null;
try {resp = call.invoke (url, "http://161.200.70.44/MyAddWS.wsdl");
} …
Parameter ret = resp.getReturnValue();Object value = ret.getValue();System.out.println("\n\n Result from SOAP Server : \n\n");System.out.println ("Answer --> " + value);…
Java Client (Continue)