<body><script type="text/javascript"> function setAttributeOnload(object, attribute, val) { if(window.addEventListener) { window.addEventListener('load', function(){ object[attribute] = val; }, false); } else { window.attachEvent('onload', function(){ object[attribute] = val; }); } } </script> <div id="navbar-iframe-container"></div> <script type="text/javascript" src="https://apis.google.com/js/platform.js"></script> <script type="text/javascript"> gapi.load("gapi.iframes:gapi.iframes.style.bubble", function() { if (gapi.iframes && gapi.iframes.getContext) { gapi.iframes.getContext().openChild({ url: 'https://www.blogger.com/navbar.g?targetBlogID\x3d8907963\x26blogName\x3dWS-Comments\x26publishMode\x3dPUBLISH_MODE_BLOGSPOT\x26navbarType\x3dBLUE\x26layoutType\x3dCLASSIC\x26searchRoot\x3dhttps://ws-comments.blogspot.com/search\x26blogLocale\x3den_US\x26v\x3d2\x26homepageUrl\x3dhttp://ws-comments.blogspot.com/\x26vt\x3d972201484635970681', where: document.getElementById("navbar-iframe-container"), id: "navbar-iframe" }); } }); </script>

WS-Comments

perspectives on open-source and web services

Monday, December 06, 2004

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.

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);

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;
}
}

0 Comments:

Post a Comment

<< Home