`

SOAP Study

阅读更多

 
 Introduction to SOAP

 

SOAP is a simple XML based protocol to let applications exchange information over HTTP.

 

 

 

SOAP Building Blocks

A SOAP message is an ordinary XML document containing the following elements:

  • A required Envelope element that identifies the XML document as a SOAP message
  • An optional Header element that contains header information
  • A required Body element that contains call and response information
  • An optional Fault element that provides information about errors that occurred while processing the message

All the elements above are declared in the default namespace for the SOAP envelope:

http://www.w3.org/2001/12/soap-envelope

and the default namespace for SOAP encoding and data types is:

http://www.w3.org/2001/12/soap-encoding

 

 

 

Syntax Rules

Here are some important syntax rules:

  • A SOAP message MUST be encoded using XML
  • A SOAP message MUST use the SOAP Envelope namespace
  • A SOAP message MUST use the SOAP Encoding namespace
  • A SOAP message must NOT contain a DTD reference
  • A SOAP message must NOT contain XML Processing Instructions

 

<?xml version="1.0"?>
<soap:Envelope
xmlns: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> 

 

 

 

The mandatory SOAP Envelope element is the root element of a SOAP message.

 

The xmlns:soap Namespace

A SOAP message must always have an Envelope element associated with the "http://www.w3.org/2001/12/soap-envelope" namespace.

If a different namespace is used, the application must generate an error and discard the message.

 

The encodingStyle Attribute

The SOAP encodingStyle attribute is used to define the data types used in the document. This attribute may appear on any SOAP element, and it will apply to that element's contents and all child elements. A SOAP message has no default encoding.


The SOAP Header Element

The optional SOAP Header element contains application specific information (like authentication, payment, etc) about the SOAP message. If the Header element is present, it must be the first child element of the Envelope element.

 

<soap:Header>
   <m:Trans xmlns:m="http://www.w3schools.com/transaction/"
       soap:mustUnderstand="1">234
   </m:Trans>
</soap:Header>

 

SOAP defines three attributes in the default namespace ("http://www.w3.org/2001/12/soap-envelope"). These attributes are: actor, mustUnderstand, and encodingStyle. The attributes defined in the SOAP Header defines how a recipient should process the SOAP message.

 

 

The encodingStyle Attribute

The SOAP encodingStyle attribute is used to define the data types used in the document. This attribute may appear on any SOAP element, and it will apply to that element's contents and all child elements. A SOAP message has no default encoding.

 

The mustUnderstand Attribute

The SOAP mustUnderstand attribute can be used to indicate whether a header entry is mandatory or optional for the recipient to process.

If you add "mustUnderstand="1" to a child element of the Header element it indicates that the receiver processing the Header must recognize the element. If the receiver does not recognize the element it must fail when processing the Header.

The actor Attribute

A SOAP message may travel from a sender to a receiver by passing different endpoints along the message path. Not all parts of the SOAP message may be intended for the ultimate endpoint of the SOAP message but, instead, may be intended for one or more of the endpoints on the message path.

The SOAP actor attribute may be used to address the Header element to a particular endpoint.

 

 

The SOAP Body Element

The required SOAP Body element contains the actual SOAP message intended for the ultimate endpoint of the message.

Immediate child elements of the SOAP Body element may be namespace-qualified. SOAP defines one element inside the Body element in the default namespace ("http://www.w3.org/2001/12/soap-envelope"). This is the SOAP Fault element, which is used to indicate error messages.

 

Request Example:

 

<soap:Body>
   <m:GetPrice xmlns:m="http://www.w3schools.com/prices">
      <m:Item>Apples</m:Item>
   </m:GetPrice>
</soap:Body>

 

Response Example:

<soap:Body>
   <m:GetPriceResponse xmlns:m="http://www.w3schools.com/prices">
      <m:Price>1.90</m:Price>
   </m:GetPriceResponse>
</soap:Body>

 

 

 

The SOAP Fault Element

An error message from a SOAP message is carried inside a Fault element.

If a Fault element is present, it must appear as a child element of the Body element. A Fault element can only appear once in a SOAP message.

The SOAP Fault element has the following sub elements:

Sub ElementDescription
<faultcode> A code for identifying the fault
<faultstring> A human readable explanation of the fault
<faultactor> Information about who caused the fault to happen
<detail>

Holds application specific error information related to the Body element

SOAP Fault Codes

The faultcode values defined below must be used in the faultcode element when describing faults:

ErrorDescription
VersionMismatch Found an invalid namespace for the SOAP Envelope element
MustUnderstand An immediate child element of the Header element, with the mustUnderstand attribute set to "1", was not understood
Client The message was incorrectly formed or contained incorrect information
Server There was a problem with the server so the message could not proceed

 

 

SOAP HTTP Binding

A SOAP method is an HTTP request/response that complies with the SOAP encoding rules.

HTTP + XML = SOAP

A SOAP request could be an HTTP POST or an HTTP GET request.

The HTTP POST request specifies at least two HTTP headers: Content-Type and Content-Length.

 

Request Example:

 

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

<?xml version="1.0"?>
<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:GetStockPrice>
      <m:StockName>IBM</m:StockName>
    </m:GetStockPrice>
  </soap:Body>
</soap:Envelope>

 

 

Response Example:

HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: nnn<?xml version="1.0"?>

<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> 

 

 

 

 

分享到:
评论

相关推荐

    casjava源码-Gradle-SOAP--A-Gradle-Case-Study:Java技术期刊上“GradleSOAP:AGradle

    在`Gradle-SOAP--A-Gradle-Case-Study-master`中,我们可以预期看到类似的组织。 2. **构建脚本** (`build.gradle`):在这个案例中,`build.gradle`文件将详细说明如何配置Gradle来处理SOAP相关的任务,比如编译...

    源码 Dr.Bob’s - XML, SOAP & Web Services Development January 2012

    SOAP..................................................................................... 39 WSDL .................................................................................... 39 XSD Data Types...

    Sun Certified Enterprise Architect for J2EE Study Guide

    7. **Web服务(Web Services)**:J2EE支持SOAP和RESTful风格的Web服务,使应用能与其他系统进行互操作。书中会涵盖WS-I(Web Services Interoperability)标准、WSDL(Web Services Description Language)和UDDI...

    flex_study_pdf

    在本PDF资料“flex_study_pdf”中,我们可以期待深入学习Flex 3这一版本的相关知识,它在当时是Flex技术的一个重要里程碑。 Flex 3是一个用于构建动态、交互性强的Web应用程序的框架,它提供了丰富的用户界面组件库...

    axis_study

    Apache Axis 是一个开源的Web服务框架,主要用于创建和部署SOAP(Simple Object Access Protocol)服务。这个框架由Apache软件基金会开发,是Java平台上广泛使用的Web服务工具。Axis的主要目标是简化Web服务的实现,...

    EJB3_study

    本资料集`EJB3_study`主要围绕EJB3的核心概念、设计模式以及实际应用展开。 ### 1. EJB3的核心概念 - **实体Bean(Entity Bean)**:代表业务对象,通常与数据库中的记录对应。EJB3引入了注解驱动的实体管理,使得...

    onvif-study-data.rar_ONVIF_onvif IPC_onvif gsoap_onvif-study-dat

    这个压缩包“onvif-study-data.rar”包含了一系列与ONVIF相关的文档,是研究ONVIF协议、特别是针对天视通(可能是一家专注于IPC,即网络摄像机的制造商)的gSOAP应用的宝贵资源。 1. **ONVIF实现说明.doc**:此文档...

    Axis2-study.zip_axis2_doc

    标题"Axis2-study.zip_axis2_doc"表明这是一个关于Axis2的压缩文件,其中可能包含了Axis2的学习资料,特别是文档形式的内容。"Axis2"是Apache软件基金会开发的一个开放源代码Web服务平台,它主要用于构建和部署Web...

    j2ee study

    这篇名为“j2ee study”的学习资料可能涵盖了J2EE的基础知识、进阶概念和实战技巧。博主Tendyming在ITEYE博客上分享了他们的学习心得,这通常会包含代码示例、问题解析和项目经验。由于链接无法直接访问,我们可以...

    SCEA Study Guide

    4. **Web服务**:包括SOAP、WSDL和UDDI,以及如何使用Java API for XML Web Services (JAX-WS)和Java API for RESTful Web Services (JAX-RS)创建和消费Web服务。 5. **SOA和Web服务**:了解服务导向架构的概念,...

    Zend Framework Certification Study Guide

    "Zend Framework Certification Study Guide" 是为准备 Zend Framework 认证考试而编写的指南,旨在帮助开发者检验和提升在框架理解和实际项目应用中的专业技能。 **认证过程** 想要获得 Zend Framework 的认证,...

    study-parent.zip

    JavaEE支持创建和消费Web服务,包括SOAP和RESTful风格的服务。JAX-WS用于SOAP服务,JAX-RS则提供了RESTful服务的支持。 10. **Servlet 3.0+的新特性** - 异步Servlet:允许在后台处理请求,提高响应速度。 - ...

    Self-Study Guide: WebSphere Studio Application Developer and Web Services

    标题"Self-Study Guide: WebSphere Studio Application Developer and Web Services"表明这是一份专注于IBM WebSphere Studio Application Developer软件及其在Web服务开发中应用的自学指南。WebSphere Studio ...

    sun certified enterprise architect for java ee study guide exam 310-051新版.rar

    该压缩包中的"Sun Certified Enterprise Architect for Java EE Study Guide Exam 310-051新版"文件,是专门为准备310-051考试的学习者设计的。 Java EE(Java Platform, Enterprise Edition),即Java企业版,是...

    android实现webservices实例以及讲解

    package com.study.ws; import java.io.IOException; import org.ksoap2.SoapEnvelope; import org.ksoap2.SoapFault; import org.ksoap2.serialization.SoapObject; import org.ksoap2.serialization....

    ocejwsd-study:Java EE 6 Web服务开发人员认证专家研究1Z0-897 OCEJWSD

    研究Java EE 6 Web Services开发人员认证专家1Z0-897 / OCEJWSD在Servlet容器中创建Web服务在Servlet容器中创建RESTful Web服务在Servlet容器中创建SOAP Web服务创建由EJB组件实现的Web服务创建由EJB组件实现的...

    Prentice.Hall.Sun.Certified.Enterprise.Architect.for.Java.EE.Study.Guide.2nd.Edition.Jan.2010.rar

    《Prentice Hall Sun Certified Enterprise Architect for Java EE Study Guide》是针对Java企业级架构师认证考试的一本权威学习指南,2010年1月的第二版。这本书深入探讨了Java企业版(Java EE)平台上的企业级架构...

    21天学通java EE 源代码

    CaseStudy-13-15.zip这部分源码可能涵盖了第13到15章的内容,可能涉及Web服务(如SOAP或RESTful API)、EJB(Enterprise JavaBeans)以及JPA(Java Persistence API)的使用。在Web服务中,读者可以学习如何创建和...

    ssh-study-01.rar_Java编程_Java_

    3. **通信模块**:这里提到的“通信模块”可能指的是应用程序与其他系统之间的交互,例如通过RESTful API、Web服务(SOAP)或消息队列(如RabbitMQ、Kafka)。使用这些通信机制,可以实现分布式系统的组件间解耦,...

Global site tag (gtag.js) - Google Analytics