web services with delphi, sep, 2008

20
Oregon Delphi User Group September, 2008

Upload: cornelius-concepts

Post on 03-Sep-2014

4.317 views

Category:

Technology


4 download

DESCRIPTION

Describes the steps necessary to build web services (both server-side and client-side) in Delphi.

TRANSCRIPT

Page 1: Web Services With Delphi, Sep, 2008

Oregon Delphi User GroupSeptember, 2008

Page 2: Web Services With Delphi, Sep, 2008

What are web services—very brieflyRemotely invokable methods with a pre-defined

APIParameters (object with properties)Return values (object with properties)SOAP XML via HTTP

Another way of saying it…“Web Services, in the general meaning of the term, are processes offered via the Web. In a typical Web Services scenario, a business application sends a request to a service at a given URL using the SOAP protocol over HTTP. The service receives the request, processes it, and returns a response.” –Harms Software

2ODUG - Web Services, Sep 2008

Page 3: Web Services With Delphi, Sep, 2008

Single store, one database, simple accounting.

3ODUG - Web Services, Sep 2008

Page 4: Web Services With Delphi, Sep, 2008

Add an ecommerce web site.

Two databases—accountant is not happy.Shipping department confused.Customers can “buy” out-of-stock items.

4ODUG - Web Services, Sep 2008

Page 5: Web Services With Delphi, Sep, 2008

Need to merge—but how?

5ODUG - Web Services, Sep 2008

Page 6: Web Services With Delphi, Sep, 2008

The answer of course for today:Web Services!

6ODUG - Web Services, Sep 2008

Page 7: Web Services With Delphi, Sep, 2008

What is needed here?Web site needs to know what inventory is

availableStore needs to collect order informationStore needs to adjust inventory levelsStore needs to ship productsStore needs to notify web site of order statusWeb site needs to display order status

7ODUG - Web Services, Sep 2008

Page 8: Web Services With Delphi, Sep, 2008

Possible web service methods:UpdateInventory

Adds or updates items to web databaseGetPendingOrders

Get list of orders pending from webGet single order details from web

UpdateOrderStatusUpdate status field and tracking number on web

8ODUG - Web Services, Sep 2008

Page 9: Web Services With Delphi, Sep, 2008

File > NewOther > Web Services > SOAP Server

ApplicationThree types

ISAPI .DLLCGI Stand-alone .EXEWeb App Debugger

Create an interfaceFile > new

Other > Web Services > SOAP Server Interface

9ODUG - Web Services, Sep 2008

Page 10: Web Services With Delphi, Sep, 2008

Four modules created__Intf.pas

Exposed methods for the web servicesIMyWebClass = class(Invokable)

__Impl.pasDelphi implementation of web servicesTMyWebClass = class(TInvokableClass,

IMyWebClass)Here’s the meat!

Data module – web service work horseMain Form – standard application

10ODUG - Web Services, Sep 2008

Page 11: Web Services With Delphi, Sep, 2008

Add interface and implementationIntf and Impl units

Build/Run once to register COM objectRun Web App Debugger, start serverVerify new web service available in browserView WSDL automatically created for us

What’s a WSDL?Web Service Description LanguageXML document describing the web service

We’ve Created a Web Service!

11ODUG - Web Services, Sep 2008

Page 12: Web Services With Delphi, Sep, 2008

Questions?

Now on to the Client…

12ODUG - Web Services, Sep 2008

Page 13: Web Services With Delphi, Sep, 2008

New standard VCL applicationFile > New

Other > Web Services > WSDL ImporterURL of web service’s WSDLNew unit created

Full Interface to web service methods!

13ODUG - Web Services, Sep 2008

Page 14: Web Services With Delphi, Sep, 2008

Call a method—see the answer—SUCCESS!Web App Debugger

View the logSee the XML packets

Get/Response – general web page requestsPOST – web service method calls

14ODUG - Web Services, Sep 2008

Page 15: Web Services With Delphi, Sep, 2008

Web Apps –vs- Windows AppsNo formStatelessMulti-user

AcronymnsHTTP – HyperText Transfer ProtocolXML – eXtended Markup LanguageSOAP – Simple Object Access ProtocolRIO – Remote Invokable ObjectWSDL – Web Service Description LanguageUDDI – Universal Description, Discovery, and

Integration

15ODUG - Web Services, Sep 2008

Page 16: Web Services With Delphi, Sep, 2008

Web ServiceAdd(a, b: Double): Double;Subtract(a, b: Double): Double;

ClientTwo edit fields, two buttons, display answer

16ODUG - Web Services, Sep 2008

Page 17: Web Services With Delphi, Sep, 2008

Database queriesArraysTRemotable class

17ODUG - Web Services, Sep 2008

Page 18: Web Services With Delphi, Sep, 2008

Packet SizeServer speedBandwidth bottleneck

Trapping XMLLogging/modifying XML on-the-fly

Use HTTPRIO from WebServicesUse TXMLDocument from Internet

Tutorial Referencehttp://exposureroom.com/members/skumar.aspx/tutorials/post/1

18ODUG - Web Services, Sep 2008

Page 19: Web Services With Delphi, Sep, 2008

eCommerceSample packetsXML Notepad

GoogleeBayAmazonFedExCDDBMapPointMore!

19ODUG - Web Services, Sep 2008

Page 20: Web Services With Delphi, Sep, 2008

20ODUG - Web Services, Sep 2008