Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Web Services

562 views

Published on

Apresentação sobre Web Services

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Web Services

  1. 1. Gustavo Loureiro dos ReisLeonardo César de Sousa CamposVictor da Silva Montalvão
  2. 2. • Componentes da Aplicação• utilizam Protocolos Abertos• Completo e Autodescrito• Disponibilizados através da Web para outras aplicações
  3. 3. Arquivo .asmx – extensão ASP.NET para XML Web Services<%@ WebService Language="VBScript" Class="TempConvert" %>Imports SystemImports System.Web.ServicesPublic 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 functionend class http://www.w3schools.com/webservices/ws_example.asp
  4. 4. Transport Protocol• HTTP, FTP, SMTPMessaging Protocol• SOAP, WS-AddressingDescription Protocol• Public Interface• WSDLDiscovery Protocol• Available Services• UDDL*
  5. 5. • Protocolo baseado em XML• Troca de informações via HTTP Blocks Envelope Header Body Fault
  6. 6. POST /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> HTTP/1.1 200 OK <m:StockName>IBM</m:StockName> Content-Type: application/soap+xml; charset=utf-8 </m:GetStockPrice> Content-Length: nnn</soap:Body> <?xml version="1.0"?></soap:Envelope> <soap:Envelope xmlns: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>
  7. 7. public 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(); } }
  8. 8. • XML-based Language for Locating and Describing Web Services
  9. 9. • JAX-WS é uma biblioteca de chamadas remotas de procedimento (RPC), que permite implementar serviços baseados nas normas XSD, WSDL e SOAP
  10. 10. ...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
  11. 11. Chamadas remotas de procedimento, passo-a-passo:
  12. 12. OBS: Definição do acordo WSDL entre cliente e servidor

×