You are on page 1of 70

Arsitektur Aplikasi

Perangkat Enterprise #12


Antonius Rachmat C, S.Kom

SOAP Background






Originally designed by Dave Winer, Don Box, Bob


Atkinson, and Mohsen Al-Ghosein in 1998 with
backing from Microsoft as an object-access
protocol, the SOAP specification is currently
maintained by the XML Protocol Working Group of
the World Wide Web Consortium.
Developed by IBM, Microsoft, Lotus, and others
Submitted to W3C - Became W3C Note in May
1998
Current Version is 1.2, See:


http://www.w3.org/TR/SOAP

SOAP (Simple Object Access Protocol)


SOAP merupakan protokol komunikasi
berbasis XML yang memperbolehkan
aplikasi saling bertukar informasi
melalui HTTP
 SOAP merupakan protokol yang
menangani web service
 SOAP digunakan untuk mengirimkan
message melalui Internet, bersifat
platform independent, and language
independent


Elemen SOAP

Elemen SOAP (2)





Elemen Envelope yang mengidentifikasi XML


dokumen sebagai SOAP message (wajib)
Elemen Header yang berisi informasi header
(opsional)






Determines how a recipient of a SOAP message should


process the message
Adds features to the SOAP message such as
authentication, message routes, additional information,
etc

Elemen Body yang berisi response (wajib)


Elemen Fault yang berisi informasi error yang
terjadi (opsional)

Plus-Minus SOAP
Plus
 Uses HTTP which is widely used and scalable
 Flexible for growth because of XML properties
 It can be used for RPC.
Minus
 Parsing of SOAP packet and mapping to objects
reduces performance
 Doesnt implement security because it relies on
HTTP

Example SOAP Request


POST /LelangService/LelangService.asmx
HTTP/1.1
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: http://tempuri.org/LelangService/LelangServiceClass/checkCC
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance
xmlns:xsd=http://www.w3.org/2001/XMLSchema
xmlns:soap=http://schemas.xmlsoap.org/soap/envelope/ >
<soap:Body>
<checkCC
xmlns="http://tempuri.org/LelangService/LelangServiceClass">
<userid>string</userid>
<tipe>string</tipe>
<no_cc>string</no_cc>
<cvv>string</cvv>
</checkCC>
</soap:Body>
</soap:Envelope>

Example SOAP Response


HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<checkCCResponse
xmlns="http://tempuri.org/LelangService/LelangServiceClass">
<checkCCResult>boolean</checkCCResult>
</checkCCResponse>
</soap:Body>
</soap:Envelope>

HTTP POST
POST /LelangService/LelangService.asmx/checkCC HTTP/1.1
Host: localhost
Content-Type: application/x-www-form-urlencoded
Content-Length: length
userid=string&tipe=string&no_cc=string&cvv=string

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<boolean xmlns="http://tempuri.org/LelangService/LelangServiceClass">
boolean
</boolean>

Aturan


SOAP Envelope menggunakan namespace




SOAPs Syntax Rules:






xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelop
e/"
SOAP harus dibuat dengan menggunakan sintaks XML
SOAP harus menggunakan SOAP Envelope namespace
SOAP tidak boleh mengandung DTD

SOAP tidak boleh mengadung XML Processing


Instruction

SOAP Skeleton

SOAP Fault



Used to carry error and/or status information


within a SOAP message
Appears within the SOAP body, if appears, it just
appears only once.

SOAP Fault Code Element

SOAP Fault Example


<soap:Envelope
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring>Internal Application Error</faultstring>
<detail xmlns:f=http://localhost/CheckCCFault>
<f:errorCode>794634</f:errorCode>
<f:errorMsg>Divide by zero</f:errorMsg>
</detail>
</soap:Fault>
</soap:Body>
</soap:Envelope>

SOAP Envelope

SOAP Header (opsional)

SOAP Body Resquest

SOAP Body Response

What is WSDL?
Stands for Web Service Description
Language
 WSDL is a document written in XML
 The document describes a Web service
 Specifies the location of the service and
the methods the service exposes
 Not a W3C Standard


Introduction


Once you develop a Web Service:


you publish its description
 and optionally a link to it in a UDDI repository
so that potential users can find it


When someone wants to use your service, they


request the WSDL file in order to:




find out the location of the service,


the function calls
and how to access them

Then they use this information in your WSDL


file to:


form a SOAP request to the computer

Why WSDL?
Without WSDL, calling syntax must be
determined from documentation that must
be provided, or from examining wire
messages
 With WSDL, the generation of proxies for
Web services is automated in a truly
language- and platform-independent way


Working of WSDL

Figure 1. A client invoking a Web service.

WSDL Elements

Big Picture of WSDL Elements

WSDL document structure

Namespace used



The XML namespace prefix are used to indicate the


namespace of the element being defined
All WSDL elements belong to the WSDL namespace,
defined as http://schemas.xmlsoap.org/wsdl/






xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd=http://www.w3.org/2001/XMLSchema
xmlns:soap=http://schemas.xmlsoap.org/wsdl/soap/
xmlns:soapenc=http://schemas.xmlsoap.org/soap/encoding/
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"

Types Section


The type element defines the data types


that are used by the web service.

<xsd:complexType name="PERSON">
<xsd:sequence>
<xsd:element name="firstName type="xsd:string"/>
<xsd:element name="lastName" type="xsd:string"/>
<xsd:element name="ageInYears" type="xsd:int"/>
</xsd:sequence>
</xsd:complexType>

Message







A message is protocol independent


There is an input or request message, which is
sent from the client to the service, and there
is a output or response message, which is sent
back the opposite way
Each <message> element contains one or
more <part> elements.
<part> element corresponds to the parameter
or a return value in the RPC call.
The part name order reflects the order of the
parameters in the RPC signature.

Messages Section




A message element defines parameters


The name of an output message element ends in
"Response" by convention
<message name="doGetCachedPage">
<part name="key type="xsd:string"/>
<part name="url" type="xsd:string"/>
</message>
<message name="doGetCachedPageResponse>
<part name="return type="xsd:base64Binary"/>
</message>
<message name="doSpellingSuggestion">
<part name="key type="xsd:string"/>
<part name="phrase type="xsd:string"/>
</message>
<message name="doSpellingSuggestionResponse">
<part name="return type="xsd:string"/>
</message>

PortTypes Section



Defines a web service, the operations that can be performed, and the
messages that are involved.
Operation defines which message is the input and which message is the
output

SOAP Binding


<soap:binding> - Signifies that the binding is bound to the SOAP


protocol format: Envelope, Header and Body

<binding >
<soap:binding transport=uri? Style=rpc|document?>
</binding>


<soap:operation> - Provides information for the document as a


whole

<binding >
<operation >
<soap:operation soapAction=uri? Style=rpc|document?>
<input> . </input>
<output> . </output>
</operation>
</binding>

SOAP Binding contd.




<soap:body> - Specifies how the message parts appear


inside the SOAP Body element

<input>
<soap:body parts=nmtokens? use=literal|encoded?
encodingStyle=uri-list? Namespace=uri?>
</input>


<soap:fault> - Specifies the contents of the contents of the


SOAP fault

<fault>
<soap:fault name=nmtoken use=literal|encoded
encodingStyle=uri-list? Namespace=uri?>
</fault>

SOAP binding contd.




<soap:header> and <soap:headerfault> - Allow headers to


be defined that are transmitted inside the Header element of
the SOAP Envelope

<input>
<soap:header message=qname part=nmtoken
use=literal|encoded? encodingStyle=uri-list? Namespace=uri?>
<soap:headerfault message=qname part=nmtoken
use=literal|encoded? encodingStyle=uri-list? Namespace=uri?>
</input>


<soap:address> - Used to give a port an address (a URI)

<binding >
<soap:address location=uri />
</binding>

Bindings Section


The binding element defines the message format


and protocol details for each port.

PortType Operation


Tipe operasi PortType:


 One-way: operation dapat menerima message
tapi tidak mengembalikan response

PortType Operation


Tipe operasi PortType:




Request-response: operation dapat menerima


message dan akan mengembalikan response

PortType Operation


Tipe operasi PortType:




Notification: operation hanya memberikan response saja

<message name=getBilAcak>
<part name=bil type=xsd:int>
</message>
<portType name=BilanganAcak>
<operation name=getBilanganAcak>
<output message=getBilAcak/>
</operation>
</portType>

Element Service


Digunakan untuk menamai keseluruhan service pada sebuah web


service beserta nama port, binding, dan lokasi web service
tersebut

<service name="GoogleSearchService">
<port name="GoogleSearchPort
binding="typens:GoogleSearchBinding">
<soap:address
location="http://api.google.com/search/beta2"/>
</port>
</service>

UDDI
Universal Description, Discovery and
Integration
 Adalah direktori/registry yang bersifat
platform independent, untuk
mendeskripsikan, menyimpan service,
bisnis dan integrasi bisnis pada Internet
yang berkomunikasi via SOAP dan WSDL.


How UDDI Works


1.

SW companies, standards
bodies, and programmers
populate the registry with
descriptions of different types
of services

2.
UDDI Business Registry

Businesses
populate
the registry
with
descriptions of
the services
they support

Business
Registrations

3.

Segrvice Type
Reistrations

UBR assigns a programmatically unique


identifier to each service and business
registration

4.

Marketplaces, search
engines, and business
apps query the registry to
discover services at other
companies

5.

Business uses this


data to facilitate
easier integration
with each other over
the Web

Komponen UDDI
 UDDI

memiliki 3 komponen:

White Pages
 Yellow Pages
 Green Pages


White Pages
Berisi Business Name
 Text Description


Contact info


list of multi-language text strings


names, phone numbers, fax numbers, web
sites

Known Identifiers


list of identifiers that a business may be known


by

Yellow Pages


Business categories


3 standard taxonomies in Version 1






Industry: NAICS (Industry codes - US Govt.)


Product/Services: UN/SPSC (ECMA)
Location: Geographical taxonomy

Implemented as name-value pairs to allow any


valid taxonomy identifier to be attached to the
business white page

Green Pages


New set of information businesses use to


describe how to do e-commerce with them


Nested model







Business processes
Service descriptions
Binding information

Programming/platform/implementation agnostic
Services can also be categorized

Keuntungan UDDI






Membuat web service-web service dapat


ditemukan/dicari oleh user-user lain yang online.
Mempermudah mencari customer baru dan
mempermudah akses pada customer lama
Mempermudah marketing dan meraih pasar
Menyelesaikan masalah customer secara cepat
dalam era ekonomi Internet.
Mendeskripsikan service dan proses bisnis dalam
satu kesatuan, terbuka, dan lingkungan yang
aman.

WEB SERVICE dengan .NET

Web Service dengan .NET




Procedure : adalah suatu kumpulan perintahperintah yang digunakan untuk suatu tujuan
tertentu dan diberi nama tertentu.




Procedure tidak mengembalikan nilai


Di dalam VB : keywordnya sub end sub
Tidak ada keyword return

Function : adalah suatu kumpulan perintahperintah yang digunakan untuk suatu tujuan
tertentu dan diberi nama tertentu serta
mengembalikan nilai tertentu keluar kepada
fungsi yang memanggilnya.




Function mengembalikan nilai


Di dalam VB : keywordnya function . end function
Ada keyword return

Contoh Procedure


Dalam VB:
Private Sub LuasPersegiPanjang(ByVal panjang as
Integer,ByVal lebar as Integer)
Dim luas as Integer
luas = panjang * lebar
Console.WriteLn(Luas = & Str(luas))
End Sub
Dalam C#:
private void LuasPersegiPanjang(int panj, int lebar){
int luas;
luas = panj * lebar;
Console.WriteLn(Luas = + Convert.ToString(luas));
}

Contoh Function


Dalam VB:
Private Function LuasPersegiPanjang(ByVal panjang as
Integer,ByVal lebar as Integer) as Integer
Return panjang*luas;
End Sub
Console.WriteLn(Luas = & LuasPersegiPanjang(5,3));

Dalam C#:
private int LuasPersegiPanjang(int panj, int lebar){
return panj*lebar;
}
Console.WriteLn(Luas = + LuasPersegiPanjang(5,3));

DEMO WEB SERVICE







NumberGuest pada Desktop


NumberGuest pada Web
DatabaseDemo pada Desktop
DatabaseDemo pada Web

Number Guest


Untuk pembuatan web service di .Net kita


perlu membuat project baru yang disebut
ASP.NET Web Service Solution

Silahkan simpan pada location seperti


misalnya:
http://localhost:8081/NumberGuest
 Kemudian klik kanan form yang ada dan
pilih View Code
 Sehingga akan muncul tempat menuliskan
code program VB
 Pada kode tersebut sudah dipersiapkan
contoh suatu method / function dalam VB,
yaitu HelloWorld


Di dalam web service kita harus membuat


fungsi-fungsi/procedure-procedure atau
method-method sesuai dengan kebutuhan
 Untuk contoh project kita, kita perlu
membuat berbagai fungsi sebagai berikut:





Acak() untuk mengacak bilangan random dari


server dan mengambilnya
isMatch(inputanUser) untuk mencocokkan
bilangan inputan user dengan bilangan hasil
random yang ada

Prinsip-prinsip Method



Jika kita mengharapkan nilai kembalian dari suatu method


gunakan function
Sedangkan jika kita tidak mengharapkan suatu nilai
kembalian dari suatu method, kita gunakan
sub/procedure/function-void
Pakailah semua method yang telah dibuat pada webservice
untuk digunakan pada program desktop atau web
application yang kita buat
Jika kita deklarasikan method yang bersifat private, maka
method tersebut tidak akan tampak dalam list method yang
ada di daftar service dalam Web Service.
Jika kita membuat method yang bersifat public, maka akan
tampak di dalam list method yang ada di daftar service
dalam Web Service.

NumberGuestWeb




Buatlah project baru pada VS.NET yaitu ASP.NET Web


Application
Kemudian desainlah!
Cara menambahkan Web Service ke project:






Di bagian solution explorer, klik kanan pada nama project


yang kita buat dan pilih menu Add Web references
Kemudian kita browse ke Web Service on the local machine
dan pilih web service yang telah kita buat
Atau dapat pula kita tuliskan di URL, misalnya:
http://localhost:8081/EnterpriseService/NumberGuest.asmx
Setelah itu isi nama pada text box Web Reference Name,
misalnya localhost
Setelah itu klik Add Reference sehingga pada bagian solution
explorer, kita bisa melihat ada Web References yang berisi
localhost

NumberGuestWeb

NumberGuestWeb


Untuk dapat menggunakan Web Service


localhost kita, kita harus
mendeklarasikannya pada bagian public
declaration, misalnya:
Private ws As localhost.NumberGuest
= New localhost.NumberGuest

NumberGuestWeb

NumberGuestDesktop
Buatlah project baru pada VS.NET yaitu
ASP.NET Windows Application
 Kemudian desainlah!
 Cara menambahkan Web Service ke
project sama dengan pada Web Client
Application
 Desainlah sebagai berikut:


NumberGuestDesktop





Pada bagian global declaration ketikkan code sebagai


berikut:
Private ws As localhost.NumberGuest = New
localhost.NumberGuest
Pada bagian Button Guest ketikkan kode sebagai berikut:
MessageBox.Show(ws.IsMatch(Val(TextBox1.Text)))
Pada bagian Button Start Over ketikkan kode sebagai
berikut:
TextBox1.Text = ""
ws.Acak()
Pada bagian Page_Load ketikkan kode sebagai berikut:
ws.Acak()

Database WebService

Database WebService


Buatlah variable private beripe string,


misal bernama strConnection yang berisi
cara koneksi database

Database WebService

Database WebService

Database WebService

Database WebService

Database WebService


Semua obyek SqlConnection, SqlDataReader,


SqlCommand, SqlDataAdapter bisa diganti
OleDbConnection, OleDbDataReader,
OleDbCommand, dan OleDbDataAdapter jika kita
ingin menggunakan database seperti
Access/Postgres/MySQL/Oracle
Untuk Web Service yang menggunakan database,
jika ingin mengembalikan data berupa sejumlah
record dari sebuah query/tabel, misalnya select *
from tabel, maka hany ada satu tipe kembalian,
yaitu obyek DataSet yang akan diterima di client
dengan obyek yang sama juga dan kemudian
bisa digunakan langsung untuk ditampilkan pada
DataList/DataGrid

You might also like