http post/get to web services / xml

mh348

Expert Member
Joined
Jun 2, 2006
Messages
4,116
Is it possible to post/get from a Web Services (xml) page? I don't really know how this works, but I'm trying to get my SpeedServices Tracking to work. SpeedServices recently upgraded their website and removed their old tracking page and that has caused a problem with tracking.

I have a site(web page) that I setup www.ParcelTrack.co.za on which I have simple forms to track parcels from various couriers. The SpeedServices & xps used to run of the same site and probably still do, I need to figure out how to setup a http post/get form to their web services.

The url for the webservices is http://165.8.13.24/SAPO_PT_WS/SAPO_PT_WS.asmx

I need to make use of the TrackParcel section, is that possible??
 

icyrus

Executive Member
Joined
Oct 5, 2005
Messages
8,609
You are going to have to write some backend code to compose the SOAP message and communicate with their web service. There are quite a few SOAP libraries floating about for most languages, which will simplify matters a bit.
 

Deenem

Expert Member
Joined
Apr 20, 2005
Messages
1,724
^^^ What he said.

What backend server are you using?

In ASP.NET it's real easy, you just add a refernce to the Web Service and you can use it like you would any other object.

If you're using PHP then there would be libraries or modules that would do the same thing.
 

mh348

Expert Member
Joined
Jun 2, 2006
Messages
4,116
^^^ What he said.

What backend server are you using?

In ASP.NET it's real easy, you just add a refernce to the Web Service and you can use it like you would any other object.

If you're using PHP then there would be libraries or modules that would do the same thing.
I'm using php, I don't think my Host supports ASP on their servers.

How do I go about doing it via php?
 

icyrus

Executive Member
Joined
Oct 5, 2005
Messages
8,609
I'm using php, I don't think my Host supports ASP on their servers.

How do I go about doing it via php?
You'll want to use PHP's SOAP extension. I haven't used PHP for a while so I can't give you much more info than this. The basic idea though is to have your form post to a php page on your server then use the tracking number the user entered to build the needed SOAP message and send it to their server using the PHP SOAP extension.
 

@udiS3

Senior Member
Joined
Feb 4, 2008
Messages
503
For each of the operations there is a request and response message example, if you click
on one of the operations. You need to compose meaningful xml and send this off as a request which you will get a valid response for.

The wsdl defines what are meaningful types and what are meaningful operations:
http://165.8.13.24/SAPO_PT_WS/SAPO_PT_WS.asmx?wsdl

In Java there are loads of tools that decompose the wsdl and provide beans and classes to support composing your message. So to with .NET.

As for PHP you going to have to find some good libraries to do this.
 

mh348

Expert Member
Joined
Jun 2, 2006
Messages
4,116
Thanks for all the replies and suggestion. It seems quite complicated, not something I'll be able to do.

I'm willing to pay someone to do it, but not too much since that website/webpage doesn't generate any money, it's just something that I stated to make it easy to track parcels for myself and later decided to share with others. As you have seen theres no ads or anyhting, just the search boxes.
 

icyrus

Executive Member
Joined
Oct 5, 2005
Messages
8,609
Thanks for all the replies and suggestion. It seems quite complicated, not something I'll be able to do.

I'm willing to pay someone to do it, but not too much since that website/webpage doesn't generate any money, it's just something that I stated to make it easy to track parcels for myself and later decided to share with others. As you have seen theres no ads or anyhting, just the search boxes.
I can help you with it, free of charge. Do you perhaps have an example parcel id that I could use for testing?

The basics of code would be:

PHP:
<?php
// Get the Parcel ID from the POST.
$parcelid = $_POST['parcelid'];

// Setup the SOAP client with the service's WSDL.
$client = new SoapClient('http://165.8.13.24/SAPO_PT_WS/SAPO_PT_WS.asmx?WSDL')

// Setup the SOAP call parameters.
$params = array('ParcelID' => $parcelid);
// Call the desired function.
$res = $client->TrackParcel($params);
?>
But it would need some testing to see what their webservice actually returns and that it all works.
 

@udiS3

Senior Member
Joined
Feb 4, 2008
Messages
503
I can help you with it, free of charge. Do you perhaps have an example parcel id that I could use for testing?

The basics of code would be:

PHP:
<?php
// Get the Parcel ID from the POST.
$parcelid = $_POST['parcelid'];

// Setup the SOAP client with the service's WSDL.
$client = new SoapClient('http://165.8.13.24/SAPO_PT_WS/SAPO_PT_WS.asmx?WSDL')

// Setup the SOAP call parameters.
$params = array('ParcelID' => $parcelid);
// Call the desired function.
$res = $client->TrackParcel($params);
?>
But it would need some testing to see what their webservice actually returns and that it all works.
@mh348 you lucky to get someone to help and for free nogal. Doncha jus love MyBB? Wouldve been able to help you out if it was java or .NET.
 

mh348

Expert Member
Joined
Jun 2, 2006
Messages
4,116
I can help you with it, free of charge. Do you perhaps have an example parcel id that I could use for testing?

The basics of code would be:

PHP:
<?php
// Get the Parcel ID from the POST.
$parcelid = $_POST['parcelid'];

// Setup the SOAP client with the service's WSDL.
$client = new SoapClient('http://165.8.13.24/SAPO_PT_WS/SAPO_PT_WS.asmx?WSDL')

// Setup the SOAP call parameters.
$params = array('ParcelID' => $parcelid);
// Call the desired function.
$res = $client->TrackParcel($params);
?>
But it would need some testing to see what their webservice actually returns and that it all works.
Hi, thanks. Thats Geat. I don't have a tracking no at the moment, but try with TA123456789ZA it should return an error stating that the no. does not exist in the db.

If you want I could go get a valid no. from the Post Office, I'll just buy a speedservices prepaid back and send it to someone so you can test.
 

icyrus

Executive Member
Joined
Oct 5, 2005
Messages
8,609
Hi, thanks. Thats Geat. I don't have a tracking no at the moment, but try with TA123456789ZA it should return an error stating that the no. does not exist in the db.
At the moment this is what I am getting back from their service:

"UODOTNET: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 10.3.28.29:31438"

I am not sure exactly what this means but it seems to be a problem on their side connecting to a local resource 10.3.28.29:31438?

I don't suppose you have a technical contact with them that can clarify if this means they're having a problem or if there is a problem with my code?

If you want I could go get a valid no. from the Post Office, I'll just buy a speedservices prepaid back and send it to someone so you can test.
I don't think that will be necessary just yet. :)
 

mh348

Expert Member
Joined
Jun 2, 2006
Messages
4,116
I don't suppose you have a technical contact with them that can clarify if this means they're having a problem or if there is a problem with my code?
I do have an email address for someone that I think is in charge of the website. I sent an email to the email address on the whois details and got forwarded to someone else. I emailed the guy twice and he hasn't replied.
 

icyrus

Executive Member
Joined
Oct 5, 2005
Messages
8,609
Their web service seems to be getting more broken by the day. Now you can't even browse to the original URL without it spitting out a whole bunch of crystalreports errors.
 

icyrus

Executive Member
Joined
Oct 5, 2005
Messages
8,609
I just checked the speed services website, and it now uses http://sms.postoffice.co.za/SAPO_PT_WS/SAPO_PT_WS.asmx

It seems to be on a different ip.
Ok, I tried the code with the new address and it appears to work:

PHP:
<?php
// Get the Parcel ID from the POST.
$parcelid = $_POST['parcelid'];

// Setup the SOAP client with the service's WSDL.
$client = new SoapClient('http://165.8.13.24/SAPO_PT_WS/SAPO_PT_WS.asmx?WSDL')

// Setup the SOAP call parameters.
$params = array('ParcelID' => $parcelid);
// Call the desired function.
$res = $client->TrackParcel($params);
$parcel_status = $res->TrackParcelResult;
?>
$parcel_status will be a string with the result of the operation, which should be Not found or the actual parcel status.

On my machine it is responding with some weird characters around the NOT FOUND message but it is there.

I hope this helps you. If you need any other help let me know.
 

mh348

Expert Member
Joined
Jun 2, 2006
Messages
4,116
Ok, I tried the code with the new address and it appears to work:

PHP:
<?php
// Get the Parcel ID from the POST.
$parcelid = $_POST['parcelid'];

// Setup the SOAP client with the service's WSDL.
$client = new SoapClient('http://165.8.13.24/SAPO_PT_WS/SAPO_PT_WS.asmx?WSDL')

// Setup the SOAP call parameters.
$params = array('ParcelID' => $parcelid);
// Call the desired function.
$res = $client->TrackParcel($params);
$parcel_status = $res->TrackParcelResult;
?>
$parcel_status will be a string with the result of the operation, which should be Not found or the actual parcel status.

On my machine it is responding with some weird characters around the NOT FOUND message but it is there.

I hope this helps you. If you need any other help let me know.
Do I just save that code as a php page and post to it ??
sorry for the noobish questions :eek:
 

icyrus

Executive Member
Joined
Oct 5, 2005
Messages
8,609
Do I just save that code as a php page and post to it ??
sorry for the noobish questions :eek:
Yeah, in essence that is what you do. However, all that the above code does is query the web service and set the return string to the variable $parcel_status. Actually displaying it to the user still needs to be done.

The easiest way to do this would be to have a second PHP page the serves as a template for the display. For example:

PHP:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Parcel Status</title>
</head>

<body>
<h3><?php print $parcel_status; ?></h3>
</body>
And save it as template.php then add the following line after $parcel_status = $res->TrackParcelResult :

PHP:
include('template.php')
As long as both files are in the same directory.

Of course you can (and should) customize the HTML to suit your site.
 

mh348

Expert Member
Joined
Jun 2, 2006
Messages
4,116
Yeah, in essence that is what you do. However, all that the above code does is query the web service and set the return string to the variable $parcel_status. Actually displaying it to the user still needs to be done.

The easiest way to do this would be to have a second PHP page the serves as a template for the display. For example:

PHP:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Parcel Status</title>
</head>

<body>
<h3><?php print $parcel_status; ?></h3>
</body>
And save it as template.php then add the following line after $parcel_status = $res->TrackParcelResult :

PHP:
include('template.php')
As long as both files are in the same directory.

Of course you can (and should) customize the HTML to suit your site.
I can't seem to get it working, I'm probably doing something wrong.

I uploaded the files to http://www.parceltrack.co.za/speedservices/

Will it be possible for you to take a look at the files and see if you can get it to work? I'll pm you the ftp login details for the site.
 
Top