Reader small image

You're reading from  Expert Delphi - Second Edition

Product typeBook
Published inFeb 2024
Reading LevelExpert
PublisherPackt
ISBN-139781805121107
Edition2nd Edition
Languages
Right arrow
Authors (2):
Marco Cantù
Marco Cantù
author image
Marco Cantù

Marco Cantù is an experienced Delphi expert, who started working with the product since its introduction in 1995. He is currently working as a Product Manager for RAD Studio at Embarcadero Technologies, an Idera company. Prior to that, Marco was a Delphi trainer and consultant for Wintech Italia. Over the years, Marco has written 20 books on Delphi, from the classic Mastering Delphi series to the recent Object Pascal Handbook. Marco has been a speaker at many Delphi and programming conferences worldwide, including over 10 Borland US Conferences, the Software Development Conference, Borland European conferences, EKON (Germany), DCon (UK), Conference to the Max (Holland), DelphiTage, the Italian Delphi Day, and a few editions of Delphi Developer Days. Marco is based in Italy.
Read more about Marco Cantù

Paweł Głowacki
Paweł Głowacki
author image
Paweł Głowacki

Paweł Głowacki was Embarcadero's European Technical Lead for Developer Tools. Previously, Paweł spent over 7 years working as a senior consultant and trainer for Delphi within Borland Education Services and CodeGear. Apart from working with Embarcadero customers across the region, he represented Embarcadero internationally as a conference and seminar speaker. Paweł passed away in mid-December 2017, but he is alive in the hearts of the Delphi developers community, worldwide.
Read more about Paweł Głowacki

View More author details
Right arrow

Integrating with Web Services

No mobile app is a lonely island. You can create a standalone mobile app with Delphi, but most of the time developers want to integrate with services to provide access to data and add the whole social dimension to the mobile user experience. In this chapter, we are going to have a tour of different technologies available in Delphi to integrate with mobile backends running in the cloud, including the HTTP native client library, accessing REST APIs, and using the Cloud API framework for integrating with cloud Web Services available on Amazon and Azure.

This chapter will cover the following points:

  • Understanding Web Services
  • Building a native HTTP client
  • Consuming XML SOAP Web Services
  • Integrating with REST Services
  • Integrating with the cloud
  • Using the AWS SDK for Delphi

The objective of this chapter is to learn how to build mobile HTTP clients and connect to Web Services and data in the cloud. This is a very broad topic...

Technical requirements

The code in this chapter uses external Web Services and cloud services and requires you to have accounts on the target systems. In most cases, a free account will be sufficient. In addition, the last demo uses the AWS SDK for Delphi, which is an add-on library. The examples in this chapter are available at https://github.com/PacktPublishing/Expert-Delphi_Second-edition.

Understanding Web Services

Not so long ago, and not in a galaxy far, far away, Sir Timothy John Berners-Lee invented the World Wide Web. In his vision for an information management system, individual documents should be hyperlinked with each other through special Uniform Resource Locators (URLs) and anyone reading a document in a web browser program should be able to jump directly to a referenced hypertext document. He was also the one who designed the Hypertext Transfer Protocol (HTTP) and implemented the first versions of web server and web browser programs, which used the HTTP protocol for communication. The fact that his ideas were – from the very beginning – open, public, and for everyone, contributed to the enormous, global success of the World Wide Web. At that time, it wasn’t obvious that the web would become something that nowadays we take for granted, opening our favorite web browser and searching for information or reading the news.

HTTP is a simple...

Building a native HTTP client

Arguably the most important network communication protocol is HTTP and its secure HTTPS version. Every operating system typically has its own HTTP client functionality built in. In the cross-platform world of Delphi programming, there is an HTTP client library, which provides uniform access to the HTTP client implementations available on different platforms.

Similar to other cross-platform libraries in Delphi, you can either work with HTTP entirely in code using types defined in the System.Net.HttpClient and System.Net.URLClient units, or you can rely on the ready-to-use components declared in the System.Net.HttpClientComponents unit and available in the Net category of Tool Palette.

Let’s give it a try and build a simple app that will allow you to enter the URL into an edit box, download data using the HTTP GET request, and display the result in a memo component. These are the steps for building this demo:

  1. Create a new blank Delphi...

Consuming XML SOAP Web Services

The starting point for implementing a SOAP Web Service client is a Web Services Description Language (WSDL) document, which specifies the web methods a given Web Service implements, including the names and types of the expected parameters. Delphi provides a WSDL Importer wizard that takes as input a WSDL file and generates an Object Pascal unit with types and methods that correspond with the functionality exposed by a SOAP Web Service. The main application logic can use the generated classes in order to issue Web Service requests and receive results returned from a remote Web Services server app.

Let’s have a look at the process of integrating with a SOAP Web Service on the example of a numeric processing service, capable of converting a number in its textual description. I found a free, open service, which is not terribly useful but is good for a demo. The WSDL file, if you want to take a look, is at https://www.dataaccess.com/webservicesserver...

Integrating with REST services

Technology does not like to stand still. It keeps evolving. Nowadays, SOAP Web Services are not as frequently used as compared to the early days, especially in comparison to REST.

Over time, the XML file format became harder and harder to process. The initially simple XML specification became more complex and the entire model has proven not flexible enough. In the meantime, the much simpler JSON became the most popular format for exchanging structured data.

The REST architecture for implementing Web Services is not as standardized as SOAP. There are several data structure and Web Service interface proposals, but none of them has gained a prominent position. The beauty of REST is that it fully adopts the underlying HTTP protocol (while SOAP is protocol agnostic) and it just uses HTTP request and response headers for structural information.

In REST, there is more freedom. Inside the REST server, there are different resources identified by their...

Integrating with the cloud

Cloud computing is a fairly broad term referring to the global trend of moving in-house or on-premise servers and even servers owned by a company and hosted in a web farm to a fully hosted service solution. The difference between traditional hosting and cloud hosting is, in the first case, you manage hardware with an operating system and application software running on it, while in the cloud scenario, you use software services, regardless of the hardware infrastructure. In other words, rather than paying for hardware, electricity, web connectivity, and perpetual or yearly software licenses, you pay for a service per minute (or at times even millisecond) of use, by traffic volume, or by some use quota. The huge advantage of cloud services is the ability to scale them up very rapidly when there is more demand and scale them down when not needed so that you end up paying proportionally to the actual usage, rather than having to allocate a large amount of resources...

Using the AWS SDK for Delphi

If you prefer to use Amazon Web Services (AWS), rather than Azure, the Delphi Cloud API offers similar capabilities and integration. However, for AWS, there is a different, much expanded, client library you can use, the AWS SDK for Delphi by Appercept (see https://www.appercept.com/appercept-aws-sdk-for-delphi). This cloud client library is freely available in the Enterprise version of Delphi and can be downloaded from GetIt.

While based on the same concepts, this client library has more extensive coverage of the core APIs, but also offers a large number of additional AWS services, including (at the time of writing):

  • Cognito (user pools)
  • Cognito (identity pools)
  • Polly
  • Simple Email Service (SESV2)
  • Simple Notification Service (SNS)
  • Simple Queue Service (SQS)
  • Simple Storage Service (S3)
  • Textract
  • Amazon Translate
  • AWS Key Management Service (AWS KMS)
  • AWS Secrets Manager

There is no room in this chapter...

Summary

In this chapter, we have examined in some detail a number of different alternative techniques for building client applications that use Web Services. We looked into the HTTP, SOAP, and REST client libraries available in Delphi. We also examined the Delphi Cloud API and the AWS SDK for Delphi.

Overall, these techniques are very important, as most applications interact with remote data and Web Services these days. Which technique you use will depend on your specific needs – the reason we offered a broad overview of the many alternatives available in Delphi rather than focusing on a specific one.

In some cases, however, you might want to build both the client and the Web Service itself. That’s the topic we’ll cover in the next two chapters, starting with the foundations and progressing with more advanced features.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Expert Delphi - Second Edition
Published in: Feb 2024Publisher: PacktISBN-13: 9781805121107
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime

Authors (2)

author image
Marco Cantù

Marco Cantù is an experienced Delphi expert, who started working with the product since its introduction in 1995. He is currently working as a Product Manager for RAD Studio at Embarcadero Technologies, an Idera company. Prior to that, Marco was a Delphi trainer and consultant for Wintech Italia. Over the years, Marco has written 20 books on Delphi, from the classic Mastering Delphi series to the recent Object Pascal Handbook. Marco has been a speaker at many Delphi and programming conferences worldwide, including over 10 Borland US Conferences, the Software Development Conference, Borland European conferences, EKON (Germany), DCon (UK), Conference to the Max (Holland), DelphiTage, the Italian Delphi Day, and a few editions of Delphi Developer Days. Marco is based in Italy.
Read more about Marco Cantù

author image
Paweł Głowacki

Paweł Głowacki was Embarcadero's European Technical Lead for Developer Tools. Previously, Paweł spent over 7 years working as a senior consultant and trainer for Delphi within Borland Education Services and CodeGear. Apart from working with Embarcadero customers across the region, he represented Embarcadero internationally as a conference and seminar speaker. Paweł passed away in mid-December 2017, but he is alive in the hearts of the Delphi developers community, worldwide.
Read more about Paweł Głowacki