Visit our Sponsor   Visit our Sponsor
delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
496 Users Online NOW
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback





Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi



Loremo - the 1.5 liter car coming in 2009




Startblatt.de






Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (14)


WEB SERVICESComponent available for this articleFormat this article printer-friendly!Bookmark function is only available for registered users!
By Lubomir ROSENSTEIN
Product:
Delphi 5.x (or higher)
Category:
Internet / Web
Skill Level:
Scoring:
Last Update:
05/31/2001
Search Keys:
delphi delphi3000 article borland vcl code-snippet DELPHI5 WEB SERVICES SOAP XML INTERNET HTTP ASP CGI FASTNET INDY WININET MSINET COM TNMHTTP MSXML XMLDOMObject WSDL ActiveX WSML MSSOAP SoapClient DELPHI-6
Times Scored:
25
Visits:
11732
Uploader: LUBOMIR ROSENSTEIN
Company:
Reference: N/A
Component Download: http://ww6.borland.com/codecentral/ccweb.exe/author?authorid=11004
 
Question/Problem/Abstract:
Web services is the latest Microsoft architecture vision and dream. Most of the other big players have already become enthusiastic about it and started diligent preparations for competence in this new direction. Even Borland decided, at the very last moment, not to stay aside. Suddenly they took out Delphi 6 after having kept quiet about it for a long time.
Answer:



POLITICS AND VISION

I haven’t had the opportunity to see the new Delphi yet, but according to the published information it offers a full support to the very base of the Web services -SOAP - neglecting the Borland MIDAS layer in favor of SOAP.

Why are Web services so enticing to the big software sharks? It is easy to understand their motivation. Web services means no more selling of products, but selling of services instead. No more software piracy. Fully protected copyright: the producer remains the sole owner of the product. The contract with the software user would be long term. And not unlike an addiction, the more the user consumes, the bigger his urge to consume. In terms of large organizations this means much money, great dependency and concentrated power. In the worst scenario Web services would lead to the programming of the consumers' brains to be dependant and thus to total control of the consumers' communications and everyday life - a mixture of a new capitalistic revolution and 'big brother'-nightmare .

One hopes that this is only a hysterical fantasy. Only the future will show the true role of the Web services in society. But there is no doubt they constitute a big change for the industry, not unlike the invention of the PC and Internet. And we, the developers, have to be prepared for it.

Here is a simple example of the software designing volution. The task is to get the result of some arithmetic operation, x+y for instance. (This is a highly abstract example; one can easily apply it to any real-life situation). Some years ago the approach to this task used to be to write some procedure like:

function HaveSum (x: integer; y: integer): integer;
begin
  Result:=x+y;
End;

After that, the OOP was invented. The new wave requested from the programmers to create, let's say ThaveSum class with object instance having 2 integer properties and GetSum method. On a design level it seemed both elegant and efficient (this is not the place to start a discussion about the advantages of OOP). The next move was a Microsoft’s one – they implemented COM and the object was not just building material, but rather a living entity. Designing a program became negotiating between all these entities to do you the favor of serving at a certain moment to achieve a certain goal rather than masonry.

It is a different matter that not all of these entities were friendly enough to serve, but the strategy was implemented – one can say to perfection – in Microsoft Office. Logically COM was educated to receive tasks from a distance, so if there was a office with 20 users who had to know how much exactly x+y was, it was enough only one of these IhaveSum Com to be produced, distributed, purchased and questioned by all these users.

And now, the Web services vision comes: not the product, but the summing service is being distributed. Every time one needs this unique service a call to the distributor has to be executed and a payment has to be processed accordingly. The software user is totally disconnected from the software product and concerned only with the desirable result this product gives (and which was the very reason for buying, or illegally copying, the software in the 'good old times' we are saying good-bye to.)

SIMPLE DELPHI 5 EXAMPLES

Two of the tree today’s pillars of the Web services: HTTP and XML are already well known to the Delphi developers. Next I intend to show different ways of implementing a webservice in Delphi 5 and I hope new examples with Delphi 6 will come very soon..

Firstly I will implement only the HTTP protocol. The server here could be a ASP or PHP page, but we are dedicated to Delphi, so the server is a Delphi CGI stand-alone executable. It will take a few minutes and only a line of code to create it (I am explaining for the very beginners):

- Choose File – New – New Web Server Application; - The CGI type is sufficient for our purposes and the easiest for debugging, although in real-life situation an ISAPI DLL may be preferable; - A new WebModule is created. Open its Action Editor and add an action. - Add the next line of code on OnAction event of this action, which has to be default:

procedure TWebModule1.WebModule1WebActionItem1Action(Sender: TObject;
  Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
begin
  Response.Content :=IntToStr( StrToIntDef(Request.QueryFields.Values['x'],0) +  
  StrToIntDef(Request.QueryFields.Values['y'],0));
end;

This way the server calculates the sum of the two variables and sends it back to the client..

There are already many different approaches to implement the HTTP protocol in Delphi. It is possible to use the WinInet API functions (you can find a good example of this in Marco Cantu’s Mastering Delphi 5) or Indy components, which will be included with Delphi 6 and are available to download at http://www.nevrona.com/Indy. But for this example I have chosen the Microsoft Internet Transfer Control 6.0, so you have to import it in Delphi in order to compile the client. The type library is MSINET.OCX and the name of the help file where more information about the control can be found is INET98.CHM. The control is very easy to use and requires again only a line of code in our example:.

procedure TForm1.Button1Click(Sender: TObject);
begin
  Label1.Caption := 
    inet1.OpenURL('http://localhost/scripts/webcalc.exe?x='+Edit1.Text+'&y=' 
      +Edit2.Text);
end;

The control sends the request and receives the answer from the server. OnStateChange event gives opportunity to obtain more information about the process:

procedure TForm1.Inet1StateChanged(Sender: TObject; State: Smallint);
begin
 case state of
  icResolvingHost:    statusbar1.Panels[0].Text :=
    ('looking up the IP address of the specified host computer’);
  icHostResolved:    statusbar1.Panels[0].Text :=
    (' successfully found the IP address of the specified host computer   ‘);
  icConnecting:       statusbar1.Panels[0].Text :=
    (' connecting to the host computer’);
  icConnected:        statusbar1.Panels[0].Text :=
    (' successfully connected to the host computer’);
  icRequesting:       statusbar1.Panels[0].Text :=
    (' sending a request to the host computer’);
  icRequestSent:      statusbar1.Panels[0].Text :=
    (' successfully sent the request’);
  icReceivingResponse: statusbar1.Panels[0].Text :=
    (' receiving a response from the host computer  ‘);
  icResponseReceived: statusbar1.Panels[0].Text :=
    (' successfully received a response from the host computer’);
  icDisconnecting:    statusbar1.Panels[0].Text :=
    (' disconnecting from the host computer’);
  icDisconnected:     statusbar1.Panels[0].Text :=
    ('successfully disconnected from the host computer’);
  icError:            statusbar1.Panels[0].Text :=
    ('An error occurred in communicating with the host computer’);
  icResponseCompleted: statusbar1.Panels[0].Text :=
    ('The request has completed and all data has been received’);
 end;
end;

Figure1: The Client

And the client application is ready. Instead of doing the calculation by itself, it will depend on the Webcalculator Server to do this operation. We have our Web service and can start offering it to everyone… The next example is one step more advanced: it uses XML to send the variables. XML cannot be frustrating even to the beginner, it is just a standardized format for storing and exchanging of data. This time I am using the post method of the TNMHTTP component you can find at Delphi FastNet palette. The command.

Web.Post('http://localhost/scripts/webCalc.exe',' '+strX+''+strY+'');

does all the job and what is different is that it sends a structured XML document. The server needs an instrument to parse it. There are again different technologies available: you can read more about this in the 'XML Parsing in Delphi' by Charlie Calvert. I use the MSXML.DLL library for XML parsing in the server, so you have to import this Microsoft library in Delphi first. Again the code is concentrated in OnAction event:

procedure TWebModule1.WebModule1WebActionItem1Action(Sender: TObject;
  Request: TWebRequest; Response: TWebResponse; var Handled: Boolean(;
var
  doc : IXMLDOMDocument;
  ElemList: IXMLDOMNodeList;
  x, y:integer;
  begin
    Doc:= CreateOleObject('Microsoft.XMLDOM') as  IXMLDOMDocument;
    Doc.loadXML (Request.ContentFields.Text );
    ElemList:= Doc.getElementsByTagName ('varX'’):
    x:= StrtoIntDef(ElemList.item[0].text,0);
    ElemList:= Doc.getElementsByTagName ('varY);
    y:= StrtoIntDef(ElemList.item[0].text,0);
    Response.content:= #10+#13+InttoStr(x+y) ;
  end;

There are many different approaches to access the document using the XMLDOMObject. The object is well documented in Microsoft XML SDK. The server is ready for use again. The XML is what makes a difference when we intend to send many different variables, not just x and y..

DELPHI 5 AND SOAP EXAMPLE

It is not true that we have to wait for Delphi 6 in order to start working with SOAP. SOAP Toolkit 2.0 can be downloaded and Web service created even with Delphi 5. In the last example here, this approach would be used for our Webcalculator..

The first step is to create a COM object, which will give the service. After that, a Web Service Description Language (WSDL) file has to be created for use in Web services. Fortunately, the SOAP Toolkit 2.0 wizard creates these files automatically. The last step is developing a Delphi application, which will consume the services. For this, the SOAP client has to be controlled from Delphi..

Let start it. The first task is to create a simple COM object, following the functionality of the previous examples. It will have only one interface and one method: the GetSum again:.

ISummer = interface(Idispatch)

     function  GetSum(const x: WideString; const y: WideString): WideString; 
       safecall;

Figure2: Our COM Webcalculator will offer the Web service.

function TSummer.GetSum(const x, y: WideString): WideString;
begin
  Result:= InttoStr(SysUtils.StrtoInt(x)+ SysUtils.StrtoInt(y);
end;

Is it almost the same as in the other examples, isn’t it? Create it like Active Server Object. This way a simple ASP will be written by Delphi, so you can test the object using it first. Compile the ActiveX DLL and publish the ASP on your server:.

Set DelphiASPObj = Server.CreateObject("Project1.Summer") 
 Response.Write ( DelphiASPObj.GetSum(Request.QueryString.Item("x"),
    Request.QueryString.Item("y")))
	Set DelphiASPObj = Nothing
  Response.End 

If everything goes well, the calculator has to work. Check by entering something like http://localhost/scripts/webcalculator.asp?x=3&y=8 in your browser and you have to receive back the answer..

Next, the SOAP toolkit has to be installed. Here is the address : Microsoft - msdn-files/027/001/580/msdncompositedoc.xml After that, choose the WSDL generator from the Toolkit menu. Supply the service name, the name of your Active X dll and your web directory, where new WSDL, WSML and asp files would be generated.
The last step is to create the client- in only 3 lines of code:.

procedure TForm1.Button1Click(Sender: Tobject);

var
  SoapClient: OleVariant;
  SoapClient := CreateOleObject('MSSOAP.SoapClient’);
  SoapClient.mssoapinit('http://localhost/scripts/sumservice.wsdl','SumService','SummerSoapPort'’);
  showmessage(SoapClient.GetSum(Edit1.Text,Edit2.Text));
end;

That is all. Congratulations! We have our SOAP Webcalculator!
It is so easy to transform this example into some more real-life model: a web service, which stores the address books of all our customers, for instance ( if you don’t believe that people are keen on storing personal or even very personal data on a long distance, you are still underestimating the business opportunities Microsoft have already developed).

Web services can be created even with Delphi 5, using HTTP and XML. Importing the Microsoft® Simple Object Access Protocol (SOAP) Toolkit 2.0 makes it possible SOAP to be used too, but the next generation Delphi promises to be a 100% SOAP compatible and to implement these new instruments, created especially for the Web services. As we are entering the Web services age we can be sure of only one thing: they will make the life of us, programmers, even more exciting.

-----
The 3 examples from this article are available to download at Borland Code Central:http://ww6.borland.com/codecentral/ccweb.exe/author?authorid=11004






Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment
What about WSDL and UDDI
    John Sotiropoulos (Jun 12 2001 10:33AM)

Great article and interesting comments (especially from MS-phobes).

Couple of things the article missed was the WSDL and UDDI. WSDL describes a web service. It's xml and the SOAP toolkit from MS will automatically generate a WSDL file for any COM component. This WSDL file can then allow non-winows SOAP toolkits (e.g. APACHE SOAP toolkit) to access the web service as if it was a Java class. Now that is progress.

Additionally, the SOAP toolkit (V2) comes with an ISAPI listener which does the job the article's ASP did. So no need to write the ASP or any HTTP related code! The listener will do the dispatching for you. The SOAP toolkit install associates WSDL files with the listener.

Finally for B2B purposes, if you want to expose the service you can register it with a UDDI registry. UDDI (www.uddi.org)  is a joint MS/IBM/Arriba initiative. It provides the yellow pages for services. You can register, browse, or search for a company, service, etc. This can be done from Delphi using the COM-based UDDI SDK from MS. see http://www.microsoft.com/downloads/release.asp?ReleaseID=30394

Because you can publish the WSDL file when registering a business, other 'consumers' can discover and use the service without having to write any wiring code. just the invokation of the methods/functions exposed in the WSDL file.


Respond

RE: What about WSDL and UDDI
edvaldo medina simão (Aug 4 2006 8:26PM)

Does it work with Windows 98?
Respond

Great Article
    Colt Taylor (May 30 2001 11:21AM)

To the author...
You obviously have a powerful command of all of the technologies you described.  Care to share a recommended reading list with a mere mortal?
Respond

OLE-Error 800A13BE
    anonymus (May 28 2001 3:01PM)

Nice article, but I can't get the Soap-Example to run: After calling the GetSum-Method the application stops with 'OLE-Error 800A13BE'. Any ideas how to fix this?

Thanks in advance!
Respond

RE: OLE-Error 800A13BE
LUBOMIR ROSENSTEIN (May 31 2001 1:21AM)

There can be a lot of reasons:
1. Have you checked the COM using simple ASP page? Does the script create an object ? Does it return results?
2.If yes, the most probable answer is that
a. your soap client is not properly installed;
b. (I suppose this is your case) - your calling does not mach the name of the service.What name have you given to it creating it using the wizard? Check your files and change the name in the calling procedure;
c. your WSDL file is not web published: check your Internet server.

Respond

Microsoft is starving
    DrMungkee XXL (May 24 2001 6:36PM)

Good old M$ is up to new tricks. They're losing face to Linux fast because it's a bettor OS (there's no argument there). Microsoft needs a new target to make its billions because they're just not making enough money to keep up with all the stock options they owe to many employees. Their solution is to move from a monopoly to a tirrany. The plan is that in about 6 years there'll be a new windows that will be based around this SOAP architecture. This new windows will be called .NET. With .NET mircrosft can monitor your EVERY move, bill you monthly for simply using your computer because you have the misfortune of using their shiny new OS. After, they will bill you because they will be the sole providers of software through their .NET networks. You still need to pay the actual company who wrote the software at this point. If you're late to pay a bill, your OS will not run, and your computer will be useless until you pay your bills.

The smarter people will use Linux and laugh at all the people using .NET who not only cry about data loss do to crashes, but data lost do to overdue bills.

I hope as programers you will see the evil in this new architecture with nothing but dissadvantages to society and stear clear. Microsoft is drowning and I wouldn't throw them a rope for $63,000,000,000.
Respond

RE: Microsoft is starving
Sven Opitz (May 30 2001 11:06AM)

> [...]and I wouldn't throw them a rope for $63,000,000,000.

I couldn't afford this rope, too ;-)
Respond

RE: Microsoft is starving
Jan Jacobs (May 31 2001 8:55AM)

Well,

I don't agree.  This is not microsoft only technology, and Microsoft is not the big bad monster that will devoure us all.

Web services are the next step after web pages.  The internet is great, but is more than webpages alone.  Web services give us the ability to extend the functionality of our applications beyond html pages.

Respond

RE: Microsoft is starving
fred montier (Jun 10 2001 12:15AM)

This guy is just another "linuxhead"...

Did have linux became a religion or something like ?

pity..pity..pity
Respond

RE: Microsoft is starving
John Sotiropoulos (Jun 12 2001 10:35AM)

Web services will allow us to at long last separate content from presentation and instead of parsing HTML pages or try to hack CGI/etc URLs; this is  not an MS consiparacy but a vision evangelised by the inventor of the web Tim Bernes-Lee, a vision often referred to as the semantic web. Sure packaged software will still be developed and sold but primarily for server-side purposes. Broadband Internet technologies like ADSL and SDSL will make desktop apps less relevant and web apps available on many different devices (from PCs to 3G smartphones)

At the same time, there is an agenda promoted by vendors (not just MS but IBM, SUN etc) to stop the free or ad-financed content and introduce subscription-based services; whether this will suceed, is a big question. MS's hailstorm is a step towards that direction, see http://www.microsoft.com/net/hailstorm.asp

But we can't ignore this massive paradigm shift because of vendor's intentions. too much good stuff in it. and thank god Delphi 6 will support these new technologies. Does anyone know whether the web services features are/will be also  available for Kylix?

Respond

I disagree
    Peter Morris (May 24 2001 10:58AM)

I don't believe that all software is going to become remote software.

The simple reason is that many (probably most) companies will not want their data stored by a third party (and accessible by them).  They will also not want their data stored on some world-wide network that may easily be hacked when they can keep it in-house on a private network.

I think remote / internet software will have a place, but it will not be a replacement.

Respond

RE: I disagree
Eber Irigoyen (May 24 2001 1:22PM)

It wouldn't be your data, it would only be the programs to handle your data, your data would stay in your hard drive
say, you would use Microsoft Word and everything would work the same, but the program would reside somewhere in the net
kindda like that
Respond

RE: I disagree
Abdulaziz Jasser (May 24 2001 1:49PM)

You’re words are perfectly right.
Respond

on the fence
anonymus (May 31 2001 5:10AM)

I don't believe that Web Services will eclipse package-based software.
While software houses, especially Microsoft will realize revenue from this newish technology, there will still be a significant number of users,
especially corporate users that opt for full licensing/ownership of software for reasons such as security, performance, scalability, reliability etc.

From a developer's perspective, I think SOAP is pretty cool and I look
forward to sinking my teeth into it. I'm a little more sceptical about .NET
and the motivations fuelling it. Some aspects of it are quite dumb-ass:
in VB7.NET, M$ are introducing features like short-cut boolean evaluation, object inheritance, and whole host of features that us Delphi
dudes have taken for granted since ways back!

One interesting thing about .NET though is the common run-time library that's supposed to be used with VB, C++ and C# - allowing debugging of
apps in any of those languages in the same kinda IDE, and portability
to other OSs coz of the Java-like JIT (which conjures up fears of painfully
slow execution).

.NET also provides garbage collection. Now, I'm not exactly sure where
I stand with regard to garbage collection, but I can't help feeling that it
would introduce unnecessary overhead to my apps, especially seeing as I have managed just fine FreeAndNil-ing my own memory.

Anyway, I don't see .NET, in it's present form, as a serious threat. DELPHI (still) RULEZ !!!!!!!!!!!
Respond














 
Sign up to consume product discounts for Bronze memberships !

read more


  Visit our Sponsor

 

  Community Ad of
E. Irigoyen
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)