Web Service TOC n Web Service n Web
Web Service
TOC n Web Service的概念 ¨ ¨ ¨ ¨ n Web. Service相关技术 ¨ ¨ n SOAP WSDL REST vs XML-RPC vs SOAP vs … DATA BINDING WS-security WS-Notification WS-Transaction…. . AJAX JMS BPEL Grid SOA
需要知道的知识 n n n XML HTTP/HTTPS SCHEMA/DTD
Web Service的概念
Web Service的基本层次结构 服务发布协议: UDDI 服务描述协议: 服务操作协议: WSDL SOAP 统一数据格式: 基础连接: XML Internet UDDI : Universal Description Discovery and Integration WSDL: Web Service Description Language SOAP : Simple Object Access Protocol Simple, Open, Broad Industry Support 简单、开放、 业界广泛支持
为什么需要Web. Service Name DBMS No. Zip State OK browser 之前 Presentation Services browser 之后 Client AP DBMS Cancel Business Logic Services Data Services Name No. Zip State OK Cancel DBMS Mobile Device Legacy DBMS Na No. me Zip Stat OKCancel e Presentation & Process Services Web Services Data Services
SOAP & WSDL
SOAP Envelope 的结构 <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>
SOAP RPC绑定 RPC调用:double add(ref double x, double y) Request对象: struct add { double x; double y; } <add> <x >33</x> <y>44</y> </add> Response对象: struct add. Response { double result; } <add. Response> <result>77</result> </add. Response>
SOAP RPC n SOAP文档内容 ¨ <soap: envelope> <soap: body> ¨ <my. Method> ¨ <x>5</x> ¨ </my. Method> ¨ </soap: body> ¨ </soap: envelope> ¨
服务调用 前置机 WSDL 2 JAVA XML 2 JAVA Class Operation 服务描述 CONTEXT XML Message SOAP消息 HTTP
实现SOAP的容器 XFIRE 1. x n Apache AXIS 1. x/2. x n SOAPLite …… n
WSDL文档框架 <wsdl: definitions name="nmtoken" target. Namespace="uri"> <import namespace="uri" location="uri"/>* <wsdl: types> ……</wsdl: types> <wsdl: message name=“nmtoken”>* ……</wsdl: message> <wsdl: port. Type name="nmtoken">* ……</wsdl: port. Type> <wsdl: binding name="nmtoken" type="qname">* ……</wsdl: binding> <wsdl: service name="nmtoken">*……</wsdl: service> </wsdl: definitions>
types元素 <wsdl: types> <wsdl: documentation. . /> <xsd: schema. . />* <-- extensibility element --> * </wsdl: types>
message元素 <wsdl: message name="nmtoken"> * n <wsdl: documentation. . /> n <part name="nmtoken" n element="qname" type="qname"/> * n </wsdl: message> n
port. Type元素--抽象操作的集合 n n n n <wsdl: port. Type name="nmtoken">* <wsdl: documentation. . /> <wsdl: operation name="nmtoken">* <wsdl: documentation. . /> <wsdl: input name="nmtoken" message="qname"> <wsdl: documentation. . /> </wsdl: input> <wsdl: output name="nmtoken" message="qname"> <wsdl: documentation. . /> </wsdl: output> <wsdl: fault name="nmtoken" message="qname"> * <wsdl: documentation. . /> </wsdl: fault> </wsdl: operation> </wsdl: port. Type>
binding元素 n n n n n <wsdl: binding name="nmtoken" type="qname">* <wsdl: documentation. . />? <-- extensibility element --> * <wsdl: operation name="nmtoken">* <wsdl: documentation. . /> ? <-- extensibility element --> * <wsdl: input> ? <wsdl: documentation. . /> ? <-- extensibility element --> </wsdl: input> <wsdl: output> ? <wsdl: documentation. . /> ? <-- extensibility element --> * </wsdl: output> <wsdl: fault name="nmtoken"> * <wsdl: documentation. . /> ? <-- extensibility element --> * </wsdl: fault> </wsdl: operation> </wsdl: binding>
service元素 n n n n <wsdl: service name="nmtoken"> * <wsdl: documentation. . />? <wsdl: port name="nmtoken" binding="qname">* <wsdl: documentation. . /> ? <-- extensibility element --> </wsdl: port> <-- extensibility element --> </wsdl: service>
n n n n n n <types> <schema…> <element name="PO" type="tns: POType"/> <complex. Type name="POType"> <element name="id" type="string/> <element name="name" type="string"/> <element name="items"> <complex. Type> <element name="item" type="tns: Item" min. Occurs="0“ max. Occurs="unbounded"/> </complex. Type> </element> </complex. Type> <complex. Type name="Item"> <element name="quantity" type="int"/> <element name="product" type="string"/> </complex. Type> <element name="Customer" type="tns: Customer. Type"/> <complex. Type name="Customer. Type"> <element name="name" type="string"/> </complex. Type> </schema> </types>
消息示例 n n <message name="PO"> <part name="po" element="tns: PO"/> <part name="customer" element="tns: Customer"/> </message> n n n <message name="P 1"> <part name=“address" type=“XSD: string"/> </message> n n n <message name="P 2"> <part name="composite" type="tns: Composite"/> </message>
端口类型定义 n n n 端口类型是一个由抽象操作和抽象消息构成的有名称的集合。 <wsdl: definitions. . > <wsdl: port. Type name="nmtoken"> * <wsdl: operation name="nmtoken"> <wsdl: input name="nmtoken"? message="qname"/> <wsdl: output name="nmtoken"? message="qname"/> <wsdl: fault name="nmtoken" message="qname"/>* </wsdl: operation> </wsdl: port. Type > </wsdl: definitions> 端口类型定义的name属性表示端口类型名称,操作定义的name 属性表示操作名称。
单向操作 n n n n n 单向操作语法: <wsdl: definitions. . > <wsdl: port. Type. . > * <wsdl: operation name="nmtoken"> <wsdl: input name="nmtoken"? message="qname"/> </wsdl: operation> </wsdl: port. Type > </wsdl: definitions> input元素指定用于单向操作的抽象消息格式。
请求响应操作 n n n 请求响应操作语法 <wsdl: definitions. . > <wsdl: port. Type. . > * <wsdl: operation name="nmtoken" parameter. Order="nmtokens"> <wsdl: input name="nmtoken"? message="qname"/> <wsdl: output name="nmtoken"? message="qname"/> <wsdl: fault name="nmtoken" message="qname"/>* </wsdl: operation> </wsdl: port. Type > </wsdl: definitions>
要求应答操作 n n n 要求应答操作语法 <wsdl: definitions. . > <wsdl: port. Type. . > * <wsdl: operation name="nmtoken" parameter. Order="nmtokens"> <wsdl: output name="nmtoken"? message="qname"/> <wsdl: input name="nmtoken"? message="qname"/> <wsdl: fault name="nmtoken" message="qname"/>* </wsdl: operation> </wsdl: port. Type > </wsdl: definitions>
通知操作语法 n <wsdl: definitions. . > n <wsdl: port. Type. . > * n <wsdl: operation name="nmtoken"> n <wsdl: output name="nmtoken"? n message="qname"/> n </wsdl: operation> n </wsdl: port. Type > n </wsdl: definitions> n
n n n n n 绑定 绑定语法如下: <wsdl: definitions. . > <wsdl: binding name="nmtoken" type="qname"> * <-- extensibility element (1) --> * <wsdl: operation name="nmtoken"> * <-- extensibility element (2) --> * <wsdl: input name="nmtoken"? > ? <-- extensibility element (3) --> </wsdl: input> <wsdl: output name="nmtoken"? > ? <-- extensibility element (4) --> * </wsdl: output> <wsdl: fault name="nmtoken"> * <-- extensibility element (5) --> * </wsdl: fault> </wsdl: operation> </wsdl: binding> </wsdl: definitions>
服务 public class my. Services { n public void my. Method (int x){ n return n } n} n
rpc/encoded样式 n WSDL文档内容 ¨ <message name="my. Method. Request"> ¨ <part name="x" type="xsd: int"/> ¨ </message> ¨ <message name="empty"/> ¨ <port. Type name="PT"> ¨ <operation name="my. Method"> ¨ <input message="my. Method. Request"/> ¨ <output message="empty"/> ¨ </operation> ¨ </port. Type>
rpc/encoded样式 n SOAP文档内容 ¨ <soap: envelope> <soap: body> ¨ <my. Method> ¨ <x xsi: type="xsd: int">5</x> ¨ </my. Method> ¨ </soap: body> ¨ </soap: envelope> ¨
2 rpc/literal样式 n WSDL文档内容 ¨ <message name="my. Method. Request"> ¨ <part name="x" type="xsd: int"/> ¨ </message> ¨ <message name="empty"/> ¨ <port. Type name="PT"> ¨ <operation name="my. Method"> ¨ <input message="my. Method. Request"/> ¨ <output message="empty"/> ¨ </operation> ¨ </port. Type>
2 rpc/literal样式 n SOAP文档内容 ¨ <soap: envelope> <soap: body> ¨ <my. Method> ¨ <x>5</x> ¨ </my. Method> ¨ </soap: body> ¨ </soap: envelope> ¨
3 document /encoded n n n n WSDL文档内容 <types> <schema> <element name="x. Element" type="xsd: int"/> </schema> </types> <message name="my. Method. Request"> <part name="x" element="x. Element"/> </message> <message name="empty"/> <port. Type name="PT"> <operation name="my. Method"> <input message="my. Method. Request"/> <output message="empty"/> </operation> </port. Type>
3 document /encoded n SOAP文档内容 n <soap: envelope> <soap: body> <x. Element xsi: type="xsd: int ">5</x. Element> </soap: body> </soap: envelope> n n
4.document /literal n n n n WSDL文档内容 <type> <schema> <element name="x. Element" type="xsd: int"/> </schema> </types> <message name="my. Method. Request"> <part name="x" element="x. Element"/> </message> <message name="empty"/> <port. Type name="PT"> <operation name="my. Method"> <input message="my. Method. Request"/> <output message="empty"/> </operation> </port. Type>
4.document /literal SOAP文档内容 n <soap: envelope> n <soap: body> n <x. Element>5</x. Element> n </soap: body> n </soap: envelope> n
Sample WSDL n sample. wsdl
开发Web Service XFire 1. 2. 1
什么是XFire? http: //xfire. codehaus. org
特性和目标 n n n n n 支持主要的Web Service标准——SOAP, WSDL, WS-I Basic Profile, WS-Addressing, WS-Security, 等等. 高性能的SOAP栈 可插入式地绑定对 POJOs, XMLBeans, JAXB 1. 1, JAXB 2. 0, and Castor的支持。 可运行在 Java 5和1. 4 平台 支持多种传输协议 - HTTP, JMS, XMPP, In-JVM, 等等. 简单易用的API 支持Spring, Pico, Plexus, and Loom 等框架. 支持JBI 支持客户端和服务器端接口自动生成 支持JAX-WS
从不同的组件中创建服务 Depository Banks Vendor Setup Vendor Process Servers Maintenance Budget (Imaging) Analysis Tool Printer S 20 -Sales Maintenance Polling Reports Calendar Due Dates General Broadcast Maintenance Invoice App Filter Stores & Mrkts Smart Plus Launcher Sales Corrections Hand Scan Apps PO Interface 定义业务服务-SOA的 基本组成者 Sales Posting Return to Vendor D 01 Post Load Billing Credit App Scorecard Bonus/HR Sales Tax Polling Cycle Physical Inventory Home Deliveries Transfers Stock Status Price Testing Counts PO Receiving Price Management System DRK Tx SKU Information Media Journal Entry Tool Kit Warranty Billing System Cellular Rollover House Charges Capital Projects Op. SS Repair Fixed Assets 找到服务的组件 BMP - Bus performance Mngt AP AIMS Reporting In-Home Repair Step 2 Store Budget Reporting EDI Coordinator PSP Data Warehouse Count Corrections Merchandise Analysis AIMS Planning Ad Expense Store Scorecard N. Writer Workspace Ad Launcher Purchase Order General Ledger Sign System Mngr Approval Batch Forcasting Ad Measurement I 35 Early Warning System SKU Rep Power. Suite Tex A SKU Selection Tool Customer Repair Tracking ABBX Rebate Transfer SKU Performance Coop Inventory Info Host to AS 400 Communication Supplier Compliance Layaways Scanning Spec Source Bus Systems - ISP Tracking CTO Spec Source SKU Tracking Mkt Reactions -Promo Analysis Price Marketing Support website POS Intercept Employee Purchase ABC Co V 04 -Sign System Prodigy Banks - ACH and Pos to Pay Plan Administrators (401 K, PCS, Life) Satellite System 1 DFK AAS P 01 Employee Masterfile P 09 - P 17 Cyb. CTS Solution Software A 04 - Cust Refund Chks On-line New Hire Entry Resumix Step 1 Warehouse Management Equifax Employee Change Notice Resource Scheduling Store Monitor Customer Perceived In-Stock I 13 - Auto Replenishment Customer Order Print Costing Cell Phones Millennium Stock Options ACH Printer PO Universal Account Reconcilliation VAN Shows Millennuim 3. 0 Tally Sheet Cobra Insertions Orders NEW Soundscan Mesa Data INVENTORY CONTROL APPS - PC OTHER APPS - PC Recon File Connect 3 PDF Transfe Connect 3 Reports Credit Cash Receipts/Credit Misc Accounting/Finance Apps - PC/NT INVENTORY CONTROL APPS - PC ACCTS REC APPS - PC Step 3 Cash Over/ Short 定义接口 Step 4 重复上述过程
Web Service相关链接 n n n http: //www. w 3. org/TR/soap/ http: //www. w 3. org/TR/wsdl/ http: //www. w 3. org/TR/UDDI/ http: //xfire. codehaus. org/ http: //ws. apache. org/axis 2
- Slides: 90