Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Coding Forum


You are currently viewing our Coding Forum as a guest. Please register to participate.
Login



Reply
Webservice request xml
Old 11-06-2009, 07:02 AM Webservice request xml
Novice Talker

Posts: 7
Name: d
Trades: 0
Hi All,

I have a question about webserve,
I have this example here
http://www.w3schools.com/webservices...nheitToCelsius

My question:
Can anyone tell me how to receive the xml answer that is being displayed in the browser in my source code as string? (so that i can parse and extract the response value).

the result is fine but my problem is that how can i make use of it as it only displays in the browser?

thanx
tropic is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-06-2009, 08:13 AM Re: Webservice request xml
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Please, do not cross post your questions.
The 2 threads have been merged into a unique one.

To answer your question, in this specific case, they use SOAP to do the request.
So, you must use a client SOAP library, and configure it to use this service.

After that, it depends of what you use on the server side to process the answer.
You cross posted in both PHP and ASP forums, so, which one do you use ?
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 11-06-2009, 08:39 AM Re: Webservice request xml
Novice Talker

Posts: 7
Name: d
Trades: 0
sorry for cross posting,

I use PHP or ASP javascript,
a solution a any of both languages would be fine

thanx
tropic is offline
Reply With Quote
View Public Profile
 
Old 11-06-2009, 10:25 AM Re: Webservice request xml
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
I'll tell you about PHP, as it's my domain.
You have to understand that SOAP abstract the XML "talk" that occurs between the server and the client.

If a method defined into the wsdl file return a string that contains the xml, it's the sole decision of the webservice maker.
In the wsdl, you can see the return type of a call, and you need to code your script in accordance.

For example, if I take the function FahrenheitToCelsius() from your wsdl, we have this
Code:
<s:element name="FahrenheitToCelsius">
    <s:complexType>
        <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="Celsius" type="s:string"/>
        </s:sequence>
    </s:complexType>
</s:element>
<s:element name="FahrenheitToCelsiusResult">
    <s:complexType>
        <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="FahrenheitToCelsiusResult" type="s:string"/>
        </s:sequence>
    </s:complexType>
</s:element>
This define that the method FahrenheitToCelsius() takes a sequence (array) in input with a paramter named "Farenheit" that contains a string.

The FahrenheitToCelsiusResult type is the answer from the server.
It's defined as a sequence too (so, an array) with an "Farenheit" index that contains a string with the returned value.

The php script to use this would be this one:
PHP Code:
<?php
$client 
= new SoapClient("http://www.w3schools.com/webservices/tempconvert.asmx?WSDL");
$answer=$client->FahrenheitToCelsius(array("Fahrenheit"=>"120"));

var_dump$answer);
?>

and it's output would be
Code:

object(stdClass)#2 (1) {   ["FahrenheitToCelsiusResult"]=>   string(16) "48.8888888888889" }
As you see, the PHP soap client encase it into an anonymous class.

You can get the XML, as stated into the PHP documentation, by turning the "trace" flag true on the instantiation of the SOAP client
PHP Code:
<?php
$client 
= new SoapClient("http://www.w3schools.com/webservices/tempconvert.asmx?WSDL", array("trace"=>true));
And in that case, you can simply get the xml answer with
PHP Code:
$xml=$client->__getLastRequest(); 
This script:
PHP Code:
<?php
$client 
= new SoapClient("http://www.w3schools.com/webservices/tempconvert.asmx?WSDL", array("trace"=>true));
$answer=$client->FahrenheitToCelsius(array("Fahrenheit"=>"120"));

//indicate to the browser that the output is XML, and not html
header('content-type: text/xml');
print(
$client->__getLastRequest());
returns this:
http://webalis.com/soap.php
__________________
Only a biker knows why a dog sticks his head out the window.

Last edited by tripy; 11-06-2009 at 10:29 AM..
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 11-09-2009, 04:25 AM Re: Webservice request xml
Banned

Posts: 3
Name: jhoneferis
Trades: 0
Two basic methods parse XML documents. One is the Document Object Model (DOM) method. When parsing an XML document with DOM, the parser reads the entire document and creates a tree-like representation of it. The second method uses SAX and parses XML documents with events. The DOM method, while sometimes easier to implement, is slower and more resource-intensive than SAX. Digester simplifies SAX parsing by providing a higher-level interface to SAX events. This interface hides much of the complexity involved in XML document navigation, allowing developers to concentrate on processing XML data instead of parsing it.
jhoneferis is offline
Reply With Quote
View Public Profile
 
Old 11-16-2009, 09:41 AM Re: Webservice request xml
Novice Talker

Posts: 7
Name: d
Trades: 0
Thanx for your comments,
any clear example with asp JavaScript ? on posting xml as to url and retrieving response ?

thanx
tropic is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Webservice request xml
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.31375 seconds with 11 queries