web service client wrapping soap in delphi

I would like to have a delphi based client from which I can access web services.
I have no experience in this, but obviously there is the wsdl file which provide informations about the service and a soap file which is used to transport the information.
I have seen an example to do this in VB Excel: Getting the google search results which could be done in less then an hour.

There should be a generic appraoch also in delphi 6+ to get to this.

Could there be a generic recipent to go step by step to utlize the following soap code in a delphi client?

This is an example soap file found among others in the web:
<?xml version="1.0" ?>
- <definitions name="TemperatureService" targetNamespace="http://www.xmethods.net/sd/TemperatureService.wsdl" xmlns:tns="http://www.xmethods.net/sd/TemperatureService.wsdl" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns="http://schemas.xmlsoap.org/wsdl/">
- <message name="getTempRequest">
  <part name="zipcode" type="xsd:string" />
  </message>
- <message name="getTempResponse">
  <part name="return" type="xsd:float" />
  </message>
- <portType name="TemperaturePortType">
- <operation name="getTemp">
  <input message="tns:getTempRequest" />
  <output message="tns:getTempResponse" />
  </operation>
  </portType>
- <binding name="TemperatureBinding" type="tns:TemperaturePortType">
  <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
- <operation name="getTemp">
  <soap:operation soapAction="" />
- <input>
  <soap:body use="encoded" namespace="urn:xmethods-Temperature" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
  </input>
- <output>
  <soap:body use="encoded" namespace="urn:xmethods-Temperature" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
  </output>
  </operation>
  </binding>
- <service name="TemperatureService">
  <documentation>Returns current temperature in a given U.S. zipcode</documentation>
- <port name="TemperaturePort" binding="tns:TemperatureBinding">
  <soap:address location="http://services.xmethods.net:80/soap/servlet/rpcrouter" />
  </port>
  </service>
  </definitions>
LVL 1
hush021299Asked:
Who is Participating?
 
moduloConnect With a Mentor Commented:
Closed, 250 points refunded.

modulo
Community Support Moderator
Experts Exchange
0
 
Lee_NoverCommented:
File - New - WebServices: WSDL Import
enter the WSDL address, click next, finish
delphi created the TemperatureService.pas file
include that file in your app and use the service like:

uses TemperatureService;

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
     with GetTemperaturePortType do
       ShowMessage(FloatToStr(getTemp(Edit1.Text)));
end;




tested with Delphi7 but should be the same in D6 :)
0
 
DragonSlayerCommented:
and that, is much much less than 1 hour ;-)
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
hush021299Author Commented:
let me try it!
0
 
hush021299Author Commented:
OK, this was almost too simple. So I tried to create a proper running example. This one runs but has some hickups.
So please help me to get it working.

Example Babelfish:
WDSL: http://www.xmethods.net/sd/2001/BabelFishService.wsdl

My code:
uses  BabelFishService;

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var s:widestring; i:integer;a,b, pc:pChar;  c:array [0..500] of char;
//more dont work!??
begin
s:=memo1.text;
for i := 1 to 500 do
c[i]:=char(s[i]);
//how to get the first char empty?
c[0]:='.';
a:=pchar(combobox1.Text);
b:=pchar(combobox2.Text);
memo2.text := BabelFishService.GetBabelFishPortType().BabelFish(a+'_'+b,(c));
end;

The problem is the conversion :How to get the chars from the memo1.text (better then this).
Furthermore i do not know where to find the translation methode shortcut e.g. en_fr  en_de (etc. more i dont know)
0
 
Lee_NoverCommented:
errr why all that nonsense code ? :)
this will do:

procedure TForm1.Button1Click(Sender: TObject);
begin
     Memo2.Text:=GetBabelFishPortType.BabelFish(ComboBox1.Text + '_' + ComboBox2.Text, Memo1.Text);
end;

about the lang codes I suggest you check the http://babelfish.altavista.com/ source code :)
0
 
hush021299Author Commented:
Nope
Address error.....an invalid character was found in text content".

If I remember right there has been something with null terminated strings...

and I have visited already the link you mentioned. There is no list of the methods e.g. what is italy_sweden??

This conversion sh.. is a problem for me. I can use text in code, but when I use an input via control, i got the converion err.
0
 
Lee_NoverCommented:
that's odd .. may as well be Delphi6 problem
can you paste the interface part of the generated method ?
mine looks like:

  BabelFishPortType = interface(IInvokable)
  ['{B04F2684-B029-834D-8A91-8366E7B7E356}']
    function  BabelFish(const translationmode: WideString; const sourcedata: WideString): WideString; stdcall;
  end;
0
 
hush021299Author Commented:
 BabelFishPortType = interface(IInvokable)
  ['{B04F2684-B029-834D-8A91-8366E7B7E356}']
    function  BabelFish(const translationmode: WideString; const sourcedata: WideString): WideString; stdcall;
  end;
..its the same!
0
 
hush021299Author Commented:
..I still owe you points.
However, I would like to have more advice for 250.
what do you think?
Basically the answer I have implemented came from the forum in about com.
However basically you have answered the question!?
0
 
Lee_NoverCommented:
I think I answered the question fully .. even gave you a step-by-step procedure and an example of usage
I don't know why delphi6 missinterpreted the service and can't test it coz I have only D7
and what was the 'answer' from about.com ?
0
 
hush021299Author Commented:
     9815.2 in reply to 9815.1

You're on the right track.  What you have there is a WSDL document.  This is a description of a webservice's exposed interfaces.  Unfortunately, it looks like you copied it out of Internet Explorer.  Next time, SAVE it instead, so you don't get those "- <..." dash symbols.  They invalidate the XML document.  I have removed them for you and pasted the result in this message for reference.

Now then!  You have a WSDL.  Save it to disk somewhere.

If you're using Delphi 7, start a new project.  Then, go to File -> New -> Other.  In the webservices tab, select WSDL IMPORTER.  Point to the file and click OK.  It will read the XML and generate a Delphi unit with all the webservice functions in it.

If you're using Delphi 8, most of these steps are pretty much the same.  Instead of File-New, you just right-click on your project references and add a web reference.

To call one of the webservice functions, you need to:

1) Use the unit.  Press Alt-F11 to do this it easily.

2) Get a handle to the interface that the unit defines.  This is done with the GET* function that was automatically generated.  For this WSDL, it describes the TemperaturePortType service, so the function here is GetTemperaturePortType().  This will return an interface of type TemperaturePortType.  You may call this function with no parameters if that's easier... they are all optional.  It may not be best, but it should work.  Try to specify them if you can, though.

3) Call any of the methods from the TemparaturePortType interface (I see that it really only has one method, getTemp()).  This automatically calls underlying methods to create an XML request according to the request type defined in the WSDL, sends the request to the URL in the WSDL via HTTP.  The web service there will read the XML, process the request, and send an XML response back, according to the response type defined in the WSDL.  The interface method will deserialize the XML response and return the value sent by the webservice.

When you don't have the WSDL document as a file, you can point the Import Wizard to the URL that publishes the WSDl instead.  It will download it automatically and generate the same unit that it would generate if you gave it a file instead.

 

<?xml version="1.0" ?>
<definitions name="TemperatureService" targetNamespace="http://www.xmethods.net/sd/TemperatureService.wsdl"

xmlns:tns="http://www.xmethods.net/sd/TemperatureService.wsdl" xmlns:xsd="http://www.w3.org/2001/XMLSchema"

xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns="http://schemas.xmlsoap.org/wsdl/">
<message name="getTempRequest">
<part name="zipcode" type="xsd:string" />
</message>
<message name="getTempResponse">
<part name="return" type="xsd:float" />
</message>
<portType name="TemperaturePortType">
<operation name="getTemp">
<input message="tns:getTempRequest" />
<output message="tns:getTempResponse" />
</operation>
</portType>
<binding name="TemperatureBinding" type="tns:TemperaturePortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
<operation name="getTemp">
<soap:operation soapAction="" />
<input>
<soap:body use="encoded" namespace="urn:xmethods-Temperature" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</input>
<output>
<soap:body use="encoded" namespace="urn:xmethods-Temperature" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</output>
</operation>
</binding>
<service name="TemperatureService">
<documentation>Returns current temperature in a given U.S. zipcode</documentation>
<port name="TemperaturePort" binding="tns:TemperatureBinding">
<soap:address location="http://services.xmethods.net:80/soap/servlet/rpcrouter" />
</port>
</service>
</definitions>
0
 
hush021299Author Commented:
Pls. close question
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.