1 / 16

Service Computing

Service Computing. Prof. Dr. Ramin Yahyapour IT & Medien Centrum 24. November 2009. SOAP Example Request. <SOAP-ENV:Envelope xmlns:SOAP-ENV="SoapEnvelopeURI" SOAP-ENV:encodingStyle="SoapEncodingURI"> <SOAP-ENV:Header> </SOAP-ENV:Header> <SOAP-ENV:Body>

naoko
Télécharger la présentation

Service Computing

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Service Computing Prof. Dr. Ramin YahyapourIT & Medien Centrum24. November 2009

  2. SOAP Example Request <SOAP-ENV:Envelope xmlns:SOAP-ENV="SoapEnvelopeURI" SOAP-ENV:encodingStyle="SoapEncodingURI"> <SOAP-ENV:Header> </SOAP-ENV:Header> <SOAP-ENV:Body> <m:GetLastTradePrice xmlns:m="ServiceURI"> <tickerSymbol>SUNW</tickerSymbol> </m:GetLastTradePrice> </SOAP-ENV:Body> </SOAP-ENV:Envelope>

  3. header Envelope body

  4. SOAP Response Format header Envelope body

  5. WSDL components

  6. Step 1: Write Java Application

  7. Generate WSDL (sqs.wsdl)

  8. Generate WSDL (sqs-interface.wsdl) message portType

  9. Generate WSDL (sqs-interface.wsdl) Binding (SOAP)

  10. UDDI and WSDL

  11. Building a Web Service public class StockQuoteService { if ( symbol.equals("XXX") ) return( (float) 55.25 ); URL url = new URL( "http://www.xmltoday.com/examples/" + "stockquote/getxmlquote.vep?s="+symbol ); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse( url.toExternalForm() ); Element elem = doc.getDocumentElement(); NodeList list = elem.getElementsByTagName( "stock_quote"); if ( list != null && list.getLength() != 0 ) { elem = (Element) list.item(0); list = elem.getElementsByTagName( "price" ); elem = (Element) list.item(0); String quoteStr = elem.getAttribute("value"); try { return Float.valueOf(quoteStr).floatValue(); } catch (NumberFormatException e1) {//Exception handling} }

  12. WSDL Definition <?xml version="1.0" encoding="UTF-8"?> <definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:interface="http://www.getquote.com/StockQuoteService-interface" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="StockQuoteService" targetNamespace="http://www.getquote.com/StockQuoteService"> <import location="http://ZHANGLJ:80/stockquote/sqs-interface.wsdl" namespace="http://www.getquote.com/StockQuoteService-interface"/> <service name="StockQuoteService"> <documentation>Stock Quote Service</documentation> <port binding="interface:StockQuoteServiceBinding" name="Demo"> <soap:address location="http://yamato:80/stockquote/services/StockQuoteService"/> </port> </service> </definitions>

  13. Service Endpoint Interface File: HelloIF.java package helloservice; import java.rmi.Remote; import java.rmi.RemoteException; public interface HelloIF extends Remote { public String sayHello(String s) throws RemoteException; }

  14. Service Endpoint Implementation File: HelloImpl.java package helloservice; public class HelloImpl implements HelloIF { public String message ="Hello"; public String sayHello(String s) { return message + s; } }

  15. Static Web Service Client File: HelloClient.java package staticstub; import javax.xml.rpc.Stub; public class HelloClient { private String endpointAddress; public static void main(String[] args) { System.out.println("Endpoint address = " + args[0]); try { Stub stub = createProxy(); stub._setProperty (javax.xml.rpc.Stub.ENDPOINT_ADDRESS_PROPERTY, args[0]); HelloIF hello = (HelloIF)stub; System.out.println(hello.sayHello("Duke!")); } catch (Exception ex) { ex.printStackTrace(); } } private static Stub createProxy() { // Note: MyHelloService_Impl is implementation-specific. return (Stub) (new MyHelloService_Impl().getHelloIFPort()); } }

  16. File: HelloClient.java J2EE Application Client package appclient; import javax.xml.rpc.Stub; import javax.naming.*; public class HelloClient { private String endpointAddress; public static void main(String[] args) { System.out.println("Endpoint address = " + args[0]); try { Context ic = new InitialContext(); MyHelloServicemyHelloService = (MyHelloService) ic.lookup("java:comp/env/service/MyJAXRPCHello"); appclient.HelloIFhelloPort = myHelloService.getHelloIFPort(); ((Stub)helloPort)._setProperty (Stub.ENDPOINT_ADDRESS_PROPERTY,args[0]); System.out.println(helloPort.sayHello("Jake!")); System.exit(0); } catch (Exception ex) { ex.printStackTrace(); System.exit(1); } } }

More Related