Advanced Web Services by vev19514

VIEWS: 243 PAGES: 24

									Advanced Web Services

       Deepak Shenoy
         Agni Software
 • Binary data transfer
 • Attachments
 • Compression
 • Encryption
 • Interoperability with web services written
   in other languages
 • Headers

6/16/2010           Agni Software               2
A brief introduction
 • SOAP – Simple Object Access Protocol
 • WSDL – Web Service Description
 • “Remote method invocation” using XML
      – Industry standard
      – platform independent
      – language independent
      – Object oriented structure
6/16/2010               Agni Software     3
Binary Transfer
 • Transfer of binary data over SOAP
 • What we will see:
      – A binary array of bytes (TByteDynArray) sent
        over the wire
      – Files sent to the server from a client, and
        downloaded back again.
      – Delphi code for the webservice and the client

6/16/2010               Agni Software               4
 • Binary Transfer demo
      – Server
            • Simple server interface passing TByteDynArrays
            • Reason for GetSOAPWebModule
            • Critical section required for global array access
      – Client
            • Convert from file to TByteDynArray and back

6/16/2010                     Agni Software                       5
Real world enhancements
 • Files as TByteDynArray: store in database
   or as server files instead
 • Convert Web App Debugger to ISAPI DLL
 • Synchronize access to the Global FileList
 • Compression: save data transfer time by
   compression of datapackets

6/16/2010          Agni Software           6
 • SOAP Data is sent in XML (character
 • Binary data is encoded into text to be sent
 • Size can be reduced by compressing the
   binary document
 • Simple compression:
      – Compress before send
      – Decompress on receive

6/16/2010             Agni Software          7
DEMO: Simple Compression
     – Generic functions using ZLib in Delphi
     – Individual parameters are

6/16/2010               Agni Software           8
HTTP/1.1 200 OK
Content-Type: text/xml
Content-Length: 594       compression
    • version="1.0"?> want to compress every
<?xmlYou may not <SOAP-ENV:Envelope xmlns:SOAP-
      single parameter (int, string, etc.)
    • The datapacket itself is large:
> <NS1:GetFileListResponse xmlns:NS1="urn:BinIntf-
ISoapBinary"> <return xsi:type="SOAP-ENC:Array" SOAP-
ENC:arrayType="xsd:string[2]"> <item>file.doc.rtf</item>
<item>file.rtf</item> </return> </NS1:GetFileListResponse>
</SOAP-ENV:Body> </SOAP-ENV:Envelope>
   6/16/2010              Agni Software                  9
DEMO: Datapacket
 • Server
     –Use SoapPascalInvoker.AfterDispatchEvent
 • Client
     –Change HTTPRio.AfterExecute
 • Savings are in datapacket size

6/16/2010            Agni Software               10
Datapacket compression
 • Server to client communication is fine – but
   extra processing is required for each call
 • Client to server communication
      –Use “Before” events – HTTPRio.BeforeExecute
       on the client,
       SoapPascalInvoker.BeforeDispatchEvent on the
      –Compress on the client
      –Decompress on the server

6/16/2010             Agni Software             11
Using HTTP Headers
 • Handle both compressed and
   uncompressed requests on the server (or
   responses on the client)
 • Add an HTTP Header indicating that a
   datapacket is compressed
      – Server: Use “Response.AddCustomHeaders”
        to add your own headers.
      – Client: Use HTTPAddRequestHeaders.
            • HTTP Handle is not exposed in code
            • Change the Delphi Source Code to expose it

6/16/2010                   Agni Software                  12
 • Binary data may not need to be part of the
   SOAP packet itself
 • SOAP Attachments: Standard available in
   SOAP 1.1
 • Attachment data arrives in a separate part
   of the transport packet
 • In HTTP: “Multipart” messages are used
 • Delphi uses MIME encoding in
6/16/2010          Agni Software           13
DEMO: Attachments
 • Only need to use the TSOAPAttachment
 • Persist the attachment file after retrieval
   using the CacheFilePersist property
 • Attachments are saved to Windows Temp
   folder by default
      – Change
        .TempDir to override

6/16/2010             Agni Software            14
Attachments: Advantages
 • SOAP Standard, so most SDKs will
   support it
 • Separate DATA from SOAP payload
 • Web server level control for

6/16/2010        Agni Software        15
SOAP Encryption
 • Encrypt data to avoid parameter exposure
   through wire taps
 • You can use HTTPS (Secure) to encrypt
      – No code changes required
 • Encrypt SOAP payloads using code
      – Parameter level
      – Datapacket level
      – (Code similar to compression code)
6/16/2010              Agni Software         16
SOAP Encryption standards

• W3C is working on a standard for
• Recommendation available at:

6/16/2010         Agni Software       17
SOAP Headers
 • SOAP data goes under the <SOAP:Body>
   tag in the datapacket
 • <SOAP:Header> is now available for you
   to add custom headers
 • Better than HTTP Headers
      – Usable on any transport
      – Standardized: part of SOAP 1.1
 • Delphi 7 supports SOAP Headers

6/16/2010              Agni Software     18
DEMO: SOAP Headers
 • ISOAPHeaders interface supports adding
   and retrieving of headers
 • Server: Create classes inherited from
   TSOAPHeader for custom headers
 • Client: Cast HTTPRio to ISOAPHeaders
   to access header information

6/16/2010         Agni Software         19
 • Many toolkits support SOAP
      – Microsoft .NET
      – Borland Delphi
      – Apache SOAP
 • Interop problems are common
      – Parameters formatted incorrectly
      – Data type differences
      – Keywords

6/16/2010                Agni Software     20
 • Interop Lab: catalog of problems between
   SOAP implementations
      – Delphi SOAP has entries there
 • Big issues with Interop
      – Namespaces, Complex types
      – Headers, Attachments
      – RPC|Encoded vs. Document|Literal

6/16/2010              Agni Software           21
 RPC|Encoded vs.
 • Delphi servers only understand
   RPC|Encoded requests
 • Delphi Clients can access both types of
 • Literal parameters: soLiteralParams in
   Converter options
 • Invoke options:
      – ioDocument: Document rules apply
      – ioLiteral: no “unwinding”
 • WSDL Importer works well by default

6/16/2010             Agni Software          22
New and upcoming areas
 • UDDI : Universal Description, Discovery
   and Integration (Webservice “directory”)
 • WSIL: Web Service Inspection Language
 • Other transports: SMTP, FTP etc.
 • SOAP 1.2 will soon be up

6/16/2010          Agni Software          23
    Thank you

   Contact me at

To top