my very first web service

okay, a little nuts-and-bolts post today. I've finished my first web service, though it is really just a web service wrapper to a tool already offered online by UPS. I guess the service I'm offering is a free implementation of their tool using WSDL and being able to hit UPS using the account I created. I guess I better say that by using my service, you agree to the terms that UPS has put on their service. and don't go around using this in production or commercial programs, as I think it's not allowed without your own account, and my IP address will more than likely change soon, breaking the WSDL URL.</p>

here's the description as generated by webservice helper. here's the WSDL for you to use.

what I've done is used cURL in PHP to make an HTTP post to UPS. I made a class that creates the correctly formed UPS access XML and request XML strings, then made another class and function that takes the inputs (as described in the WSDL) and returns an XML string. then I just added the proper documentation in the class (for ws-helper), and dropped that class into ws-helper's designated directory, and voila. it generated the WSDL and accepts the soap requests.

the code to consume this service in PHP 5 is pretty easy too, if you have configured PHP with --enable-soap, that is.

$lukeUPSRateService = SoapClient('http://68.0.120.127:8888/wshelper/service.php?class=upsRateRequest&wsdl');

$returnXML = $lukeUPSRateService->performUPSRateRequest($fromZip, $height, $length, $toZip, $weight, $width);</p>

then you could do whatever you want with the XML...like, say...

(un-tested code follows)

$upsXMLObject = simplexml_load_string($returnXML);

$cheapestRate = 100000;

for($i=0; i<$upsXMLObject->RatedShipment.length; $i++){

if($upsXMLObject->RatedShipment[i]->TotalCharges->MonetaryValue < $cheapestRate){ $cheapestRate = $upsXMLObject->RatedShipment[i]->TotalCharges->MonetaryValue;

}

}
</div>

Question or comment about this post? Tell me on GitHub.

my very first web service / groovecoder by groovecoder is licensed under a Creative Commons Attribution-ShareAlike CC BY-SA
my very first web service / groovecoder by groovecoder is licensed under a Creative Commons Attribution-ShareAlike CC BY-SA