Post on 21-Jan-2016
description
SOAP
Simple Object Access Protocol
Apakah SOAP?
• Saat ini web adalah komunikasi antara manusia dan aplikasi.
• SOAP adalah komunikasi aplikasi ke aplikasi• SOAP adalah lightweight protocol untuk
pertukaran informasi yg terstruktur dalam lingkungan desentralisasi dan terdistribusi.
• SOAP menggunakan XML technologies dalam mendefinisikan framework messagingnya
• framework ini dirancang independen terhadap berbagai model programming
• SOAP adalah communication protocol• SOAP adalah a format untuk sending
messages• SOAP dirancang untuk komunikasi via Internet• SOAP adalah platform independent• SOAP adalah language independent• SOAP adalah simple and extensible• SOAP bisa melewati firewalls• SOAP adalah W3C standard
SOAP Architecture
• Spesifikasi SOAP terdiri dari 4 bagian:– SOAP envelope: menjelaskan format dari SOAP
message.– SOAP encoding: menggambarkan dari
representasi data yang dikirim dalam sebuah pesan.
– SOAP RPC: mendefinisikan bagaimana SOAP message dapat mengeksekusi remote procedure calls (RPCs).
– SOAP binding framework: mendefinisikan protocol yang digunakan SOAP messages yang dikirim oleh aplikasi.
One way message
Request response
SOAP format
• SOAP message terdiri dari tiga bagian:– SOAP Envelope– SOAP Header
(optional)– SOAP Body
Contoh apache
Apache SOAPservice:
HelloService.java
Apache SOAP rpcrouter servlet
Apache SOAP client: HelloClient.java
Jakarta Tomcat server
SOAP request:Service name: urn:HelloWorldMethod name: sayHelloParameter: firstName=“Yuhong”
lastName=“YanSOAP response:
Return value: “Yuhong Yan, welcome to SOAP”
“Yuhong Yan, Welcome to SOAP…”sayHello(“Yuhong”,”Yan)
12
3
4
5Http POST
Http GET
SOAP Envelope
• SOAP Envelope mendefinisikan keseluruhan framework untuk menjawab– apa yang didalam message dan – siapa yang terlibat
• Envelope adalah top element dari XML document yang perepresentasikan message. – Envelope element selalu menjadi root element dari
SOAP message. – Envelope element terdiri dari
• optional Header element • Dan mandatory Body element.
SOAP Envelope Code
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Header> <!-- optional -->
<!-- header blocks go here... --> </soap:Header> <soap:Body>
<!-- payload or Fault element goes here... --> </soap:Body>
</soap:Envelope>
Envelope element
penggunaan xmlns:soap namespace selalu menggunakan http://www.w3.org/2001/12/soap-envelope
EncodingStyle• SOAP encodingStyle attribute digunakan untuk mendefinisikan
type data yang digunakan dalam dokumen.• attribute ini bisa muncul pada setiap SOAP element, dan
berpengaruh hanya pada elemen tersebut dan childnya • SOAP message tidak mempunyai default encoding.
SOAP Header
• Header element adalah generic container untuk informasi kontrol
• Bisa berupa beberapa elements dari beberapa namespace
• Header berisi informasi proses dari message
• Header adalah optional
SOAP Header
<soap:Header>
<!-- security credentials -->
<s:credentials xmlns:s="urn:examples-org:security"> <username>dave</username> <password>evad</password>
</s:credentials>
</soap:Header>
Body
• Elemen body menjelaskan messagenya<soap:Body>
<x:TransferFunds xmlns:x="urn:examples-org:banking">
<from>22-342439</from> <to>98-283843</to> <amount>100.00</amount>
</x:TransferFunds> </soap:Body>
Contoh requestSOAP Message Embedded in HTTP Request:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAPENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <SOAP-ENV:Body> <m:GetLastTradePrice xmlns:m="Some-URI"> <symbol>DIS</symbol> </m:GetLastTradePrice> </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Contoh responseSOAP Message Embedded in HTTP Response:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> <SOAP-ENV:Body> <m:GetLastTradePriceResponse xmlns:m="Some-URI"> <Price>34.5</Price> </m:GetLastTradePriceResponse> </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
SOAP Security
• SOAP specification tidak mendefinisikan encryption untukk XML Web Services.
• Diserahkan kepada implementer dari SOAP protocol.
• Encryption tergantung dari transport protocol • apakah transport protocol tersebut support
secure communication? • cost dari enkripsi semua data dibandingan
dengan sebagian data?
Contoh
<%@ WebService Language="C#" Class="CreditCardService" %>
using System.Web.Services;
public class CreditCardService { [WebMethod]
[EncryptionExtension(Encrypt=EncryptMode.Response)] public string GetCreditCardNumber() {
return "MC: 4111-1111-1111-1111"; }
}
Request yg dienkripsi
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetCreditCardNumber xmlns="http://tempuri.org/" />
</soap:Body>
</soap:Envelope>
Response yg dienkripsi
<soap:Body>
<GetCreditCardNumber xmlns="http://tempuri.org/">
<GetCreditCardNumberResult>83 151 243 32 53 95 86 13 190 134 188 241 198 209 72 114 122 38 180 34 194 138 16 97 221 195 239 86 26 152 94 27
</GetCreditCardNumberResult>
</GetCreditCardNumber>
</soap:Body>
SOAP Fault Element
• Error mesage dari SOAP mesage dimasukkan kedalam Fault element.
• (optional) jika Fault element ada, maka harus muncul sebagai elemen child pada Body element.
• Fault element hanya muncul sekali dalam SOAP message.
SOAP Fault Element
SOAP Fault element mempunyai sub elements:• <faultcode >
A code for identifying the fault
• <faultstring > A human readable explanation of the fault
• <faultactor > information about who caused the fault to happen URI value identifying the source
• <detail> error information related only to the Body element. if not present then indicates that the fault is not related to the Bodyelement.
faultcode
Contoh
HTTP
• HTTP communicates over TCP/IP.• An HTTP client connects to an HTTP server
using TCP.• After establishing a connection, the client can
send an HTTP request message to the server:
POST /item HTTP/1.1Host: 189.123.345.239Content-Type: text/plainContent-Length: 200
HTTP
• The server then processes the request and sends an HTTP response back to the client.
• The response contains a status code that indicates the status of the request:
SOAP HTTP Binding
• A SOAP method is an HTTP request/response that complies with the SOAP encoding rules.
HTTP + XML = SOAP
• A SOAP request could be an HTTP POST or an HTTP GET request.
• POST -- Send• GET -- Retrieve
SOAP request and response
• The Content-Type header for a SOAP request and response defines– the MIME type for the message and– the character encoding (optional)
• used for the XML body of the request or response.
SOAP request and response
• The Content-Length header for a SOAP request and response specifies the number of bytes in the body of the request or response.
Contoh • GetStockPrice request is sent to a server. The request has a
StockName parameter, and a Price parameter will be returned in the response. The namespace for the function is defined in http://www.example.org/stock address.
• The SOAP request: