web services

21
Gustavo Loureiro dos Reis Leonardo César de Sousa Campos Victor da Silva Montalvão Web Service s

Upload: victor-montalvao

Post on 09-Dec-2014

689 views

Category:

Technology


2 download

DESCRIPTION

Apresentação sobre Web Services

TRANSCRIPT

Page 1: Web Services

Gustavo Loureiro dos ReisLeonardo César de Sousa CamposVictor da Silva Montalvão

Web

Services

Page 2: Web Services

O que é um Web Service?

• Componentes da Aplicação

• utilizam Protocolos Abertos

• Completo e Autodescrito

• Disponibilizados através da Web para outras aplicações

Page 3: Web Services

Exemplo de Web Service

Arquivo .asmx – extensão ASP.NET para XML Web Services<%@ WebService Language="VBScript" Class="TempConvert" %>

Imports SystemImports System.Web.Services

Public Class TempConvert :Inherits WebService

<WebMethod()> Public Function FahrenheitToCelsius(ByVal Fahrenheit As String) As String dim fahr fahr=trim(replace(Fahrenheit,",",".")) if fahr="" or IsNumeric(fahr)=false then return "Error" return ((((fahr) - 32) / 9) * 5)end function

<WebMethod()> Public Function CelsiusToFahrenheit(ByVal Celsius As String) As String dim cel cel=trim(replace(Celsius,",",".")) if cel="" or IsNumeric(cel)=false then return "Error" return ((((cel) * 9) / 5) + 32)end function

end class

http://www.w3schools.com/webservices/ws_example.asp

Page 4: Web Services

Formato XML

Protocolos Abertos

Como Funcionam

Page 5: Web Services

Protocol StackTransport Protocol• HTTP, FTP, SMTP

Messaging Protocol• SOAP, WS-Addressing

Description Protocol• Public Interface• WSDL

Discovery Protocol• Available Services• UDDL*

Page 6: Web Services

• Protocolo baseado em XML• Troca de informações via HTTP

SOAPSimple Object Access Protocol

Blocks

Envelope

Header

Body

Fault

<?xml version="1.0"?><soap:Envelopexmlns:soap="http://www.w3.org/2001/12/soap-envelope"soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">

<soap:Header>...</soap:Header>

<soap:Body>...  <soap:Fault>...  </soap:Fault></soap:Body>

</soap:Envelope>

Page 7: Web Services

SOAP ExamplePOST /InStock HTTP/1.1Host: www.example.orgContent-Type: application/soap+xml; charset=utf-8Content-Length: nnn

<?xml version="1.0"?><soap:Envelopexmlns:soap="http://www.w3.org/2001/12/soap-envelope"soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">

<soap:Body xmlns:m="http://www.example.org/stock">  <m:GetStockPrice>    <m:StockName>IBM</m:StockName>  </m:GetStockPrice></soap:Body>

</soap:Envelope>

HTTP/1.1 200 OKContent-Type: application/soap+xml; charset=utf-8Content-Length: nnn

<?xml version="1.0"?><soap:Envelopexmlns:soap="http://www.w3.org/2001/12/soap-envelope"soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">

<soap:Body xmlns:m="http://www.example.org/stock">  <m:GetStockPriceResponse>    <m:Price>34.5</m:Price>  </m:GetStockPriceResponse></soap:Body>

</soap:Envelope>

SOAP Request

SOAP Response

Page 8: Web Services

SOAP & JAVApublic HTTPRequest()    {        try {            HttpClient httpclient = new DefaultHttpClient();            String body="Data";            String bodyLength=new Integer(body.length()).toString();            System.out.println(bodyLength);

            URI uri=new URI("SOMEURL?Param1=1234&Param2=abcd");            HttpPost httpPost = new HttpPost(uri);            httpPost.addHeader( "SOAPAction", strReferenceToSoapActionValue );            StringEntity entity = new StringEntity(body, "text/xml",HTTP.DEFAULT_CONTENT_CHARSET);            httpPost.setEntity(entity);

            RequestWrapper requestWrapper=new RequestWrapper(httpPost);            requestWrapper.setMethod("POST"); requestWrapper.setHeader( "SOAPAction", strReferenceToSoapActionValue );            requestWrapper.removeHeaders("Host");            requestWrapper.setHeader("Host", “...");                      HttpResponse response = httpclient.execute(requestWrapper);        } catch (Exception e) { e.printStackTrace();     }    }

Page 9: Web Services

WSDL

• XML-based Language for Locating and Describing Web Services

Web Services Description Language

Page 10: Web Services

WSDL Componentes

Tipos<types>

Mensagem<message>

Operações<operation>

Tipos de Porta<port-Type>

Vinculo

Page 11: Web Services

WSDL Namespaces

Elemento<definitions>

Elemento<types>

Elemento<import>

Elemento<operation> e <port-Type>

Elemento<binding>

Elemento<service> e <port>

Page 12: Web Services

WSDL EXAMPLE

Server send response

Page 13: Web Services

UDDIUniversal Description, Discovery & Integration

Directory for storing information and interfaces (WSDL)

Communicates via SOAP

Page 14: Web Services

JAX-WSJava API XML for Web Services

• JAX-WS é uma biblioteca de chamadas remotas de procedimento (RPC), que permite implementar serviços baseados nas normas XSD, WSDL e SOAP

Page 15: Web Services

JAX-WS pode......Definir o mapeamento de

WSDL para Java e vice-versa

... implementar Web Services partindo de um contrato WSDL ou de código Java

...criar código cliente de invocação de Web Services

Page 16: Web Services

Chamadas remotas de procedimento, passo-a-passo:

JAX-WS Esquema

Page 17: Web Services

JAX-WS Esquema 2.0

OBS: Definição do acordo WSDL entre cliente e servidor

Page 18: Web Services

JAX-WS Exemplo Endpoint

Page 19: Web Services

JAX-WS Exemplo Endpoint

Page 20: Web Services

JAX-WS Exemplo Client

Page 21: Web Services

FIM