Chapter 29- Introduction to Web Services and SOAP.ppt
《Chapter 29- Introduction to Web Services and SOAP.ppt》由会员分享,可在线阅读,更多相关《Chapter 29- Introduction to Web Services and SOAP.ppt(20页珍藏版)》请在麦多课文档分享上搜索。
1、Chapter 29: Introduction to Web Services and SOAP,Outline 29.1 Introduction 29.2 Simple Object Access Protocol (SOAP) 29.3 SOAP Weather Service,29.1 Introduction,SOAP Simple Object Access Protocol Promote interoperability Communication among different software systems. Provides XML communication in
2、many Web services Web Services Exposes public interfaces usable by Web applications,29.2 Simple Object Access Protocol (SOAP),SOAP HTTP-XML-based protocol Enables application to communicate over Internet Uses XML documents called messages SOAP message contains an envelope Describes messages content
3、and intended recipient Ability to make a Remote Procedure Call (RPC) Request to another machine to run a task,Fig. 29.1 Class SimpleService. Line 4 Lines 6-12,1 / Fig. 29.1: SimpleService.java 2 / Implementation for the requested method on the server 3 4 public class SimpleService 5 6 public String
4、getWelcome( String message ) throws Exception 7 8 String text = 9 “Welcome to SOAP!nHere is your message: “ + message; 10 11 return text; / response 12 13 ,29.2 Simple Object Access Protocol (SOAP) (cont.),Fig. 29.2 SOAP package administration tool.,29.2 Simple Object Access Protocol (SOAP) (cont.),
5、Fig. 29.3 Description of deployed service.,Fig. 29.4 Client making a SOAP request (part 1). Lines 10-11 Line 13 Line 17 Lines 27-28 Lines 31-33,1 / Fig. 29.4 : GetMessage.java 2 / Program that makes a SOAP RPC 3 4 / import Java packages 5 import java.io.*; 6 import .*; 7 import java.util.*; 8 9 / im
6、port third-party packages 10 import org.apache.soap.*; 11 import org.apache.soap.rpc.*; 12 13 public class GetMessage 14 15 / main method 16 public static void main( String args ) 17 String encodingStyleURI = Constants.NS_URI_SOAP_ENC; 18 String message; 19 20 if ( args.length != 0 ) 21 message = ar
7、gs 0 ; 22 else 23 message = “Thanks!“; 24 25 / attempt SOAP remote procedure call 26 try 27 URL url = new URL( 28 “http:/localhost:8080/soap/servlet/rpcrouter“ ); 29 30 / build call 31 Call remoteMethod = new Call(); 32 remoteMethod.setTargetObjectURI( 33 “urn:xml-simple-message“ ); 34,Fig. 29.4 Cli
8、ent making a SOAP request (part 2). Lines 40-44 Line 48 Lines 51-57 Lines 60-63,35 / set name of remote method to be invoked 36 remoteMethod.setMethodName( “getWelcome“ ); 37 remoteMethod.setEncodingStyleURI( encodingStyleURI ); 38 39 / set parameters for remote method 40 Vector parameters = new Vec
9、tor(); 41 42 parameters.addElement( new Parameter( “message“, 43 String.class, message, null ) ); 44 remoteMethod.setParams( parameters ); 45 Response response; 46 47 / invoke remote method 48 response = remoteMethod.invoke( url, “ ); 49 50 / get response 51 if ( response.generatedFault() ) 52 Fault
10、 fault = response.getFault(); 53 54 System.err.println( “CALL FAILED:nFault Code = “ 55 + fault.getFaultCode()+ “nFault String = “ 56 + fault.getFaultString() ); 57 58 59 else 60 Parameter result = response.getReturnValue(); 61 62 / display result of call 63 System.out.println( result.getValue() );
11、64 65 66,Fig. 29.4 Client making a SOAP request (part 3).,67 / catch malformed URL exception 68 catch ( MalformedURLException malformedURLException ) 69 malformedURLException.printStackTrace(); 70 System.exit( 1 ); 71 72 73 / catch SOAPException 74 catch ( SOAPException soapException ) 75 System.err
12、.println( “Error message: “ + 76 soapException.getMessage() ); 77 System.exit( 1 ); 78 79 80 ,java GetMessage Welcome to SOAP! Here is your message: Thanks!,java GetMessage “my message” Welcome to SOAP! Here is your message: my message,29.3 SOAP Weather Service,SOAP Weather Service Web service Modif
13、ication of RMI-based Weather Service (Chapter 13) Use SOAP RPC instead of Java RMI Send information from server to client,Fig. 29.5 SOAP implementation of class Weather-Service (part 1). Line 11,1 / Fig. 29.5: WeatherService.java 2 / WeatherService provides a method to retrieve weather 3 / informati
14、on from the National Weather Service. 4 package com.deitel.advjhtp1.soap.weather; 5 6 / Java core packages 7 import java.io.*; 8 import .URL; 9 import java.util.*; 10 11 public class WeatherService 12 13 private Vector weatherInformation; / WeatherBean objects 14 15 / get weather information from NW
15、S 16 private void updateWeatherConditions() 17 18 try 19 System.out.println( “Update weather information.“ ); 20 21 / National Weather Service Travelers Forecast page 22 URL url = new URL( 23 “http:/iwin.nws.noaa.gov/iwin/us/traveler.html“ ); 24 25 / set up text input stream to read Web page content
16、s 26 BufferedReader in = new BufferedReader( 27 new InputStreamReader( url.openStream() ) ); 28 29 / helps determine starting point of data on Web page 30 String separator = “TAV12“; 31 32 / locate separator string in Web page 33 while ( !in.readLine().startsWith( separator ) ) 34 ; / do nothing 35,
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
2000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- CHAPTER29INTRODUCTIONTOWEBSERVICESANDSOAPPPT

链接地址:http://www.mydoc123.com/p-379700.html