View
1.670
Download
5
Category
Tags:
Preview:
DESCRIPTION
โดย อ.ประพจน์ สุขมานนท์
Citation preview
Web Service Overview
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
Web Application
3.Web Service
2.Dynamic
1.Static
HTTP request
Web Application ยุคที& 1 : Static Web Page
Web Browser Web Server
http://www.prapoj.com/current.html
Web Pages
HTTP response
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
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
Distributed Computing
JavaWorld
Programming World!
MicrosoftWorld
Distributed Computing
.dll
ASP
VBC#
.NET
C++
EJB
Java
Java
Java
Java Java
Java
Web Service
.dll
ASP
VBC#
.NET
C++
EJB
Java
Java
Java
Java Java
Java
Web ServiceWeb Service
WSDLWSDL
What is Web Service?
Web Service?
� Application หรือโปรแกรม(หรือ Function)ซึ�งทําหน้าที�อยา่งใดอยา่งหนึ�งในลกัษณะให้บริการ(Service) โดยจะถกูเรียกใช้งานจาก Application หรือโปรแกรมอื�นๆผา่นทาง Web (Web Server โดยอาศยั SOAP Protocol) การให้บริการของ Web Service นั (น จะมีเอกสารที�อธิบายคณุสมบตัขิองบริการกํากบัไว้(WSDL) และมีการนําเสนอให้สาธารณชนรับทราบ(UDDI) ผู้ ใช้บริการจงึสามารถที�จะค้นหาบริการของ Web Service ตา่งๆได้โดยไมจ่ําเป็นต้องรู้ที�อยู่จริงของ Application หรือโปรแกรมที�ให้บริการ Web Service นั (นๆ
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
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
� สร้าง Web Service โดยการพฒันาแบบ Manual หรือใช้เครื�องมือ (Tool) ในการ Generate เราจะได้เอกสาร WSDL บรรยายคณุลกัษณะของ Web Service นั (นๆ
� ทําการ Publish ในสว่นของ Web Service ไปที� UDDI เพื�อให้บคุคลทั�วไปสามารถค้นหา Web Service ที�เราพฒันาขึ (นมาได้
ขั :นตอนในการพัฒนา Web Service
� ค้นหาบริการ Web Service ผา่น UDDI ซึ�งทําให้เราได้ข้อมลูเกี�ยวกบัประเภทบริการ ที�ตั (งของบริการ และเอกสาร WSDL บรรยายคณุลกัษณะของบริการนั (นๆ
� ตดิตอ่ขอใช้บริการ Web Service โดยใช้ SOAP Protocol (SOAP Request)ด้วยการเขียนโปรแกรมขึ (นมาเรียกใช้ Method ของ Web Service นั (นๆโดยอาศยัข้อมลูที�อยูใ่นเอกสาร WSDL
� ผู้ให้บริการสง่ผลลพัธ์กลบัมาในรูปของ XML(SOAP Response)
ขั :นตอนในการเรียกใช้ Web Service
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
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
Web Service Components
Web Service = WSDL + UDDI + SOAP
UDDI Business Registry
Search
Consume
Publis
h
Web Service
WSDLSOAP
UDDI
� Web Service Description Language เป็นภาษาที�ใช้อธิบายคณุลกัษณะของ Web Service และวิธีในการตดิตอ่กบั Web Service โดยใช้ไวยากรณ์ของภาษา XML
WSDL
� 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
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
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.
WSDL
� The main structure of a WSDL document looks like this:
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.
portType and message Example
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.
� 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
UDDI Example : XMETHODS
www.webservicex.net
� Simple Object Access Protocol เป็น Protocol ที�ใช้ในการเข้าถงึ Object หรือ Component อยา่งง่ายๆ
� SOAP เป็น Protocol ที�อาศยัไวยากรณ์ของภาษา XML
SOAP
SOAP
� SOAP supports distributed computing with XML by providing an effective mechanism for exchanging messages and accessing remote objects via XML
SOAP Message ExampleSOAP Request
SOAP Response
� 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
� 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
� Using SOAP Toolkit From Microsoft� Download at http://msdn.microsoft.com
� MyAdd.dll -> � plus2num.wsdl(WSDL file)
Generate Web Service from COM Component
SOAP Toolkit 3.0 WSDL Generator
<?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
#!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
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
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)
Recommended