"; print_r($test1); print_r($test2); echo ""; **/ // Instantiate the server $server = new soap_server(); // Create the WSDL $wsdl_addr = 'http://www.hirdweb.com/webservice/20100710_server.php'; $server->configureWSDL('HirdWeb Basic Webservice Example','HirdWeb Basic Webservice Example', $wsdl_addr); // COMPLEX TYPES FOR THE WEBSERVICE FUNCTIONS // ************************************************************************* // Status Message Array ++++++++++++++++++++++++++++++++++++++++++ $server->wsdl->addComplexType('status_mssg','complexType','struct','all','', array( 'status' => array('name' => 'status', 'type' => 'xsd:string'), 'message' => array('name' => 'message', 'type' => 'xsd:string') ) ); // showTaxes types ++++++++++++++++++++++++++++++++++++++++++ $server->wsdl->addComplexType('taxes','complexType','struct','all','', array( 'price' => array('name' => 'price', 'type' => 'xsd:float', 'minOccurs' => "0"), 'tax' => array('name' => 'tax', 'type' => 'xsd:float', 'minOccurs' => "0"), 'total' => array('name' => 'total', 'type' => 'xsd:float', 'minOccurs' => "0"), 'state' => array('name' => 'state', 'type' => 'xsd:string', 'minOccurs' => "0"), ) ); $server->wsdl->addComplexType('showTaxes','complexType','struct','all','', array( 'status' => array('name' => 'head', 'type' => 'tns:status_mssg'), 'taxes' => array('name' => 'message', 'type' => 'tns:taxes') ) ); // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // showPhrases types ++++++++++++++++++++++++++++++++++++++++++ $server->wsdl->addComplexType('showPhrases','complexType','struct','all','', array( 'status' => array('name' => 'head', 'type' => 'tns:status_mssg'), 'phrase' => array('name' => 'message', 'type' => 'xsd:string') ) ); // ************************************************************************* // ================================================ // === showPhrases register $in = array( 'id' => 'xsd:string', 'name' => 'xsd:string', ); $out = array('return' => 'tns:showPhrases'); $namespace = 'uri:hirdwebservice'; $soapaction = 'uri:hirdwebservice/showPhrases'; $doc = 'Shows a phrase from Shakespeare and replaces the name with the supplied name. ID is a number from 0 - 4'; $server->register('showPhrases', $in, $out, $namespace, $soapaction, 'rpc', 'encoded', $doc); // ================================================ // ================================================ // === showTaxes register $in = array( 'price' => 'xsd:string', 'state' => 'xsd:string', ); $out = array('return' => 'tns:showTaxes'); $namespace = 'uri:hirdwebservice'; $soapaction = 'uri:hirdwebservice/showTaxes'; $doc = 'Shows the taxes based on state taxes. Currently, the only states available in this are: AZ,AL,AK, CA, OR, WA, UT, ID, WY, Defaults to CA if no state is provided.'; $server->register('showTaxes', $in, $out, $namespace, $soapaction, 'rpc', 'encoded', $doc); // ================================================ $server->service($HTTP_RAW_POST_DATA); exit; // **** Function for the webservice function showPhrases($id, $name){ require('items.php'); // check for empty parameters if ( ($name == '') || (!isset($name)) ) { return error("partial"); } if ( $id == 100 ) { return error("not_found"); } // place all validation code here if ( ($id < 0) || ($id > 4) ){ return error('bounds'); } // Check the name for swear words if ( strtolower($name) == 'ass'){ return error('custom', '', 'Please do not use drunken sailor language when using the webservice.'); } // replace all the needles with the name $phrase = preg_replace("/NnnnnnnnnN/", $name, $phrases[$id]); $fin_data['status'] = array('status'=>'ok','message'=>''); $fin_data['phrase'] = $phrase; return $fin_data; } function showTaxes($price, $state = "ca"){ require('items.php'); // Make sure the state is lowercase $state = strtolower($state); // Check the array keys to validate $validate = array_keys($tax_rates); // place all validation code here if ( strlen($state) > 2 ){ return error('custom', '', 'The state that was passed is not in the correct format. It should only be 2 characters'); } if ( !in_array($state, $validate) ){ // return an error return error("not_found"); } if ( $price < 0 ){ return error('less_than_zero'); } if ( $price == '' ){ return error('empty'); } $tax = $tax_rates[$state] * $price; $final_price = $tax + $price; // set the array $final = array( 'price' => $price, 'tax' => money_format('%i',$tax), 'total' => money_format('%i',$final_price), 'state' => $states[$state], ); $fin_data['status'] = array('status'=>'ok','message'=>''); $fin_data['taxes'] = $final; return $fin_data; } function error($err, $struct = 'phrase', $message = ''){ $error['status']['status']='error'; $error[$struct]= ''; switch ($err) { case "empty": $error['status']['message']='There was nothing passed to the webservice, so nothing can be returned.'; break; case "partial": $error['status']['message']="Not all required parameters were passed, so the webservice can not return any information."; break; case "not_found": $error['status']['message']='The parameter you passed was not found, please try again.'; break; case "bounds": $error['status']['message']='The ID that was passed is out of the allowable boundaries. Please try your request again within the allowable range.'; break; case "less_than_zero": $error['status']['message']='The number recieved is less than zero, and will not work with this service. Please double check the number and try again.'; break; case 'custom': $error['status']['message'] = $message; break; default: $error['status']['message'] = 'There was a problem with your request, please try again.'; break; } return $error; } ?>