Sunteți pe pagina 1din 5

 

Delphi XE8
XML and SOAP
Web Services
for Windows (plus Mac and Mobile clients)

Delphi XE8 - XML, SOAP & Web Services Development


1st XE8 Edition, May 2015 for customers of Bob Swart

Bob Swart (aka Dr.Bob)


Bob Swart Training & Consultancy (eBob42)
http://www.eBob42.com
Delphi XML, SOAP & Web Services

Table of Contents
1. XML Programming 1
XML................................................................................................. 1
XML Elements and Attributes..................................................... 2
XML Namespaces..................................................................... 2
XML Schema ........................................................................... 2
Generating XML Schemas ......................................................... 3
Validating XML Schemas ........................................................... 6
TXMLDocument ................................................................................. 6
IDOMDocument vs. IXMLDocument ............................................ 9
TXMLDocument Programming ............................................................. 10
XML FireMonkey TreeView......................................................... 15
TXMLDocument on Mac OS X .................................................... 17
Deployment .................................................................... 18
TXMLDocument on iOS ............................................................. 19
TXMLDocument on Android ....................................................... 21
XML VCL TreeView ................................................................... 23
TXMLDocument as Windows Service........................................... 25
XML Data Binding .............................................................................. 27
Generated Code ...................................................................... 31
Delphi XML Mapper ............................................................................ 35
The XML Mapping Tool.............................................................. 35
Selecting Nodes ...................................................................... 36
Create and Test Transformation................................................. 38
XMLTransform......................................................................... 40
XML Mapping on OS X .............................................................. 44
XML Mapping on iOS and Android............................................... 45
Mapping Updates..................................................................... 46
TXMLTransformClient ............................................................... 47
XSLT ............................................................................................... 47
XSL Transformations ................................................................ 47
MSXSL ................................................................................... 48
Some examples of XSLT.................................................... 48
Default XSLT Templates ........................................................... 50
Our own XSLT Processor........................................................... 50
XML and XSL .......................................................................... 50
XMLData property ............................................................ 51
FileName property............................................................ 51
XML property................................................................... 51
XSLT Processor ....................................................................... 52
Alternative Approach ........................................................ 53
Summary ......................................................................................... 53

2. Web Services: SOAP & WSDL 54


Web Services .................................................................................... 54
SOAP ..................................................................................... 54
WSDL .................................................................................... 54
XSD Data Types ...................................................................... 56
SOAP and XML ........................................................................ 56
Building Delphi Web Services .............................................................. 57
Debug and ISAPI ..................................................................... 60
Second target (stand-alone) .............................................. 61

Bob Swart (Bob@eBob42.com) - ii - May 2015


Delphi XML, SOAP & Web Services

SOAP Web Module............................................................ 66


SOAP Server Interface ............................................................. 67
TRemotable ............................................................................ 70
SOAP Server Implementation .................................................... 71
Stand-alone SOAP Server VCL Project .................................................. 74
Consuming Web Services.................................................................... 76
SOAP Client ............................................................................ 77
Using GetIEcho ....................................................................... 81
Using THTTPRIO ...................................................................... 86
WSDL vs. SOAP....................................................................... 87
AdminEnabled ......................................................................... 88
GetIEcho Implementation ......................................................... 91
Conversion Web Services.................................................................... 92
TemperatureIntf ...................................................................... 94
TemperatureImpl .................................................................... 94
Debugging Web Services .................................................................... 95
Web Service Client................................................................... 96
Server Breakpoints .................................................................. 97
CodeSite and Web Services....................................................... 98
Deployment on Windows Server 2003 and IIS 6 .................................... 99
Enabling ISAPI / CGI................................................................ 99
Virtual Directory ...................................................................... 100
SSL Certificates................................................................................. 103
SSL and IIS6 on Windows Server 2003....................................... 103
Installing SSL Certificates ......................................................... 106
Deployment on Windows Server 2008 and IIS7 ........................... 107
Deploying on Windows Server 2012 ........................................... 112
Certificates on Windows Server 2012.......................................... 114
Tracing Web Services......................................................................... 119
Returning XML ........................................................................ 120
SOAP and Exceptions ......................................................................... 121
Echo Interface unit .................................................................. 121
Echo implementation unit ......................................................... 122
Echo import unit...................................................................... 122
Extending SOAP Exceptions....................................................... 123
SOAP and Databases ......................................................................... 124
Database Client....................................................................... 126
Extra Data Module ................................................................... 128
Alternative to data module: web module ..................................... 130
SOAP Attachments ............................................................................ 130
Receiving SOAP Attachments .................................................... 133
Non-Blocking SOAP Clients ................................................................. 135
Non-Blocking with TTask .......................................................... 138
Summary ......................................................................................... 139
Exercises.......................................................................................... 139
Exercise #1 ............................................................................ 139
Exercise #2 ............................................................................ 140
Exercise #3 ............................................................................ 140
Exercise #4 ............................................................................ 140
Exercise #5 ............................................................................ 140
Exercise #6 ............................................................................ 140
Exercise #7 ............................................................................ 140
Exercise #8 ............................................................................ 140

Bob Swart Training & Consultancy - iii - www.drbob42.com


Delphi XML, SOAP & Web Services

3. SOAP and Security 141


SSL Certificates................................................................................. 141
Web Service Example......................................................................... 141
SourceCodeIntf................................................................ 141
SourceCodeImpl .............................................................. 142
Importing Secure Web Service ........................................... 143
Summary ......................................................................................... 144
Exercises.......................................................................................... 144
Exercise #1 ............................................................................ 144
Exercise #2 ............................................................................ 144
Exercise #3 ............................................................................ 144

4. Case Study: Automatic Updates 145


Specifications.................................................................................... 145
Update Manager................................................................................ 145
Update Manager Web Service .................................................... 146
Update Manager Interface......................................................... 146
Update Manager Implementation ............................................... 147
Update Manager Client ....................................................................... 150
Comparing File Versions ........................................................... 152
Installing Updates.................................................................... 153
Restarting .............................................................................. 154
Run Only Once ........................................................................ 155
Automatic Updates ............................................................................ 156
TTrayIcon............................................................................... 156
Automatic Kick Off!.................................................................. 159
Additional Error Checking.......................................................... 160
Summary ......................................................................................... 161

5. Case Study: EU VAT Checking 162


EU Rules .......................................................................................... 162
VAT Number validation ............................................................. 162
VAT Number Validation Web Service........................................... 163
VAT Number Validation............................................................. 167
Summary ......................................................................................... 168

Bob Swart (Bob@eBob42.com) - iv - May 2015


Delphi XML, SOAP & Web Services

Appendix - Answers to Exercises 169


2. Web Services: SOAP & WSDL .......................................................... 169
Exercise #1 ............................................................................ 169
Answer to Exercise #1 ............................................................. 169
Exercise #2 ............................................................................ 169
Answer to Exercise #2 ............................................................. 169
Exercise #3 ............................................................................ 170
Answer to Exercise #3 ............................................................. 170
Exercise #4 ............................................................................ 171
Answer to Exercise #4 ............................................................. 171
Exercise #5 ............................................................................ 171
Answer to Exercise #5 ............................................................. 171
Exercise #6 ............................................................................ 172
Answer to Exercise #6 ............................................................. 172
Exercise #7 ............................................................................ 173
Answer to Exercise #7 ............................................................. 173
Exercise #8 ............................................................................ 174
Answer to Exercise #8 ............................................................. 174
3. SOAP and Security......................................................................... 174
Exercise #1 ............................................................................ 175
Answer to Exercise #1 ............................................................. 175
Exercise #2 ............................................................................ 175
Answer to Exercise #2 ............................................................. 175
Exercise #3 ............................................................................ 176
Answer to Exercise #3 ............................................................. 176

The information in this courseware manual is © 2001-2015 by drs. Robert E.


(Bob) Swart of Bob Swart Training & Consultancy. All Rights Reserved.
The information in this courseware manual is presented to the best of my knowledge at
the time of writing. However, in case of errors or omissions, I welcome your feedback or
comments (by e-mail) as Bob Swart Training & Consultancy cannot be held responsible for
any damage that results from using the information in this manual or the example source
code snippets. Thanks in advance for your understanding.

Bob Swart Training & Consultancy -v- www.drbob42.com

S-ar putea să vă placă și