.NET and SOAP

Post on 06-Jan-2016

78 views 0 download

Tags:

description

.NET and SOAP. An Overview of SOAP. By Raghavendra Aekka. Overview. Introduction SOAP Message format SOAP Request SOAP response SOAP Data types SOAP-HTTP binding SOAP-RPC SOAP Fault Element Conclusion. Introduction. - PowerPoint PPT Presentation

transcript

.NET and SOAP

An Overview of SOAP

By Raghavendra Aekka

Overview

Introduction SOAP Message format SOAP Request SOAP response SOAP Data types SOAP-HTTP binding SOAP-RPC SOAP Fault Element Conclusion

Introduction

SOAP is an XML-based protocol for exchanging information between computers.

Primary focus of SOAP is Remote Procedure Calls transported via HTTP.

SOAP is platform and language independent as it is entirely written in XML.

For example, a SOAP Java client running on Linux or a Perl client running on Solaris can connect to a Microsoft SOAP server running on Windows 2000

SOAP Contains Four Parts:The SOAP envelope construct Defines an overall framework to express what is in a

message, who should deal with it, and whether it is optional or mandatory.

The SOAP encoding rules Defines a serialization mechanism that can be used to

exchange instances of application-defined datatypes.

The SOAP RPC representation Defines a convention that can be used to represent

remote procedure calls and responses.

The SOAP binding Defines a convention to exchange SOAP envelopes

between peers using an underlying protocol for transport.

SOAP Message Format

SOAP Request<SOAP-ENV:Envelope xmlns:SOAP-ENV=“http://schemas.xmlsoap.org/soap/envelope/SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/”> <SOAP-ENV:Header> <t:transId xmlns:t=“http://a.com/trans”>345</t:transId> </SOAP-ENV:Header> <SOAP-ENV:Body> <m:Add xmlns:m=“http://a.com/Calculator”> <n1>3</n1> <n2>4</n2> </m:Add> </SOAP-ENV:Body></SOAP-ENV:Envelope>

SOAP Response

<SOAP-ENV:Envelope

xmlns:SOAP-ENV=“http://schemas.xmlsoap.org/soap/envelope/”

SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/”>

<SOAP-ENV:Header>

<t:transId xmlns:t=“http://a.com/trans”>345</t:transId>

</SOAP-ENV:Header>

<SOAP-ENV:Body>

<m:AddResponse xmlns:m=“http://a.com/Calculator”>

<result>7</result>

</m:AddResponse>

</SOAP-ENV:Body>

</SOAP-ENV:Envelope>

SOAP Data types

Types are either simple (scalar) or compoundwhich is a composite of several parts Simple Type A "simple type" is a class of simple values

SOAP uses all the types found in the section"Built-in data types" of XML Schema

A simple value is represented as character data,that is, without any sub-elements

Simple Type Example

<element name="age" type="int"/><element name="height" type="float"/><element name="displacement" type="negativeInteger"/><element name="color">  <simpleType base="xsd:string">    <enumeration value="Green"/>    <enumeration value="Blue"/>  </simpleType></element>

Compound type• A “compound” type is a class of compound values• Each related value is potentially distinguished by a role name,

ordinal or both (accessor)• Supports traditional types like structs and arrays

Struct Type

A compound value in which accessor name is the only distinction among member values, and no accessor has the same name as any other

<e:Book>

<author> William Shakespeare</author>

<Title> The Tempest</Title>

</e:Book>

Array type A compound value in which ordinal position serves as

the only distinction among member values.

<SOAP-ENC:Array SOAP-ENC:arrayType="xyz:Order[2]">   <Order>       <Product>Apple</Product>       <Price>1.56</Price>   </Order>   <Order>       <Product>Peach</Product>       <Price>1.48</Price>   </Order></SOAP-ENC:Array>

SOAP-HTTP A binding of SOAP to a transport protocol is a

description of how a SOAP message is to be sent using that transport protocol

The typical binding for SOAP is HTTP

SOAP can use GET or POST. With GET, the request is not a SOAP message but the response is a SOAP message, with POST both request and response are SOAP messages

SOAP uses the same error and status codes as those used in HTTP so that HTTP responses can be

directly interpreted by a SOAP module.

HTTP RequestPOST /StockQuote HTTP/1.1Host: www.stockquoteserver.comContent-Type: text/xml; charset="utf-8"Content-Length: nnnnSOAPAction: "GetLastTradePrice“

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"

SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">

<SOAP-ENV:Body><m:GetLastTradePrice xmlns:m="Some-URI"><symbol>DIS</symbol></m:GetLastTradePrice></SOAP-ENV:Body></SOAP-ENV:Envelope>

HTTP ResponseHTTP/1.1 200 OKContent-Type: text/xml; charset="utf-8"Content-Length: nnnn

<SOAP-ENV:Envelope xmlns:SOAP-ENV= "http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle= “http://schemas.xmlsoap.org/soap/encoding/"/> <SOAP-ENV:Body> <m:GetLastTradePriceResponse xmlns:m="Some-URI"> <Price>34.5</Price> </m:GetLastTradePriceResponse> </SOAP-ENV:Body></SOAP-ENV:Envelope>

SOAP-RPC

SOAP messages are basically one-way transmissions from a sender to a receiver.

However they are often combined to implement request/response mechanisms.

A few conventions must be followed todo RPC using SOAP Areduced, RPC-based view of the SOAP

message. Only the body portions of the SOAP request and response envelopes are shown.

Request <SOAP-ENV:Body> <m:GetLastTradePrice xmlns:m="some-URI"> <symbol>DEF</Symbol> </m:GetLastTradePrice></SOAP-ENV:Body>

Response <SOAP-ENV:Body> <m:GetLastTradePriceResponse xmlns:m="some-URI"> <price>22.50</price> </m: GetLastTradePriceResponse></SOAP-ENV:Body>

SOAP Fault ElementUsed to carry error and/or status information within a

SOAP messageAppears within the SOAP body

Defines the following:

faultcode (mandatory) algorithmic mechanism for identifying the fault defined in the SOAP spec

Faultstring (mandatory) human readable explanation of the fault

SOAP Fault…

faultactor (optional) information about who caused the fault to

happen URI value identifying the source

Detail error information related only to the Body

element. If not present then indicates that the fault is

not related to the Body element.

SOAP Fault example<SOAP-ENV:Envelope xmlns:SOAP-ENV=“http://schemas.xmlsoap.org/soap/envelope/”

SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/”>

<SOAP-ENV:Body> <SOAP-ENV:Fault> <faultcode>SOAP-ENV:Server</faultcode> <faultstring>Internal Application Error</faultstring> <detail xmlns:f=“http://www.a.com/CalculatorFault”> <f:errorCode>794634</f:errorCode> <f:errorMsg>Divide by zero</f:errorMsg> </detail> </SOAP-ENV:Fault> </SOAP-ENV:Body></SOAP-ENV:Envelope>

SOAP Implementations

Apache SOAP

Open source, based on IBM SOAP4J

Microsoft SOAP toolkit COM implementation, for COM-compliant

languages

SOAP::Lite for Perl

ConclusionSOAP provides a basic mechanism for: encapsulating messages into an XML document.

mapping the XML document with the SOAP message into an HTTP request.

transforming RPC calls into SOAP messages.

SOAP takes advantage of the standardization of XML toresolve problems of data representation and serialization.