function requestBags() { /* Generate a random number for the purchase order*/ $randNum = rand() % 99; /* Requested date is two weeks from today*/ $reqDate = mktime(0, 0, 0, date("m"), date("d") + 14, date("Y")); $reqDateStr = date("Y/m/d", $reqDate); /* The payload string*/ $requestPayloadString = <<<XML <po:Order xmlns:po="http://www.back_packers.com/ws/purchaseorder"> <po:OrderId>po-{$randNum}</po:OrderId> <po:ReqDate>{$reqDateStr}</po:ReqDate> <po:Design> <po:FileName>design.jpg</po:FileName> <po:Image><xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:myid1"></xop:Include></po:Image> </po:Design> </po:Order> XML; try { global $request_str; global $response_str; /* Load the design*/ $f = file_get_contents("./design.jpg"); /* Build the message*/ $requestMessage = new WSMessage($requestPayloadString, array("to" => "http://localhost/solutions/store/manuf_service.php", "action" => "http://www.back_packers.com/purchaseOrder", "attachments" => array("myid1" => $f))); /* Load certificates and keys*/ $rec_cert = ws_get_cert_from_file("keys/bob_cert.cert"); $my_cert = ws_get_cert_from_file("keys/alice_cert.cert"); $my_key = ws_get_key_from_file("keys/alice_key.pem"); /* Load policy file*/ $policy_xml = file_get_contents("policy.xml"); $policy = new WSPolicy($policy_xml); /* Ceate a security token with reqd configurations*/ $sec_token = new WSSecurityToken(array("user" => "Alice", "password" => "abcd!1234", "passwordType" => "Digest", "privateKey" => $my_key, "certificate" => $my_cert, "receiverCertificate" => $rec_cert)); /* Create a new client*/ $client = new WSClient(array("useWSA" => TRUE, "useMTOM" => FALSE, "policy" => $policy, "securityToken" => $sec_token)); /* Request*/ $responseMessage = $client->request($requestMessage); /* to track the messages */ $request_str = $client->getLastRequest(); $response_str = $client->getLastResponse(); $request_str = format_xml($request_str); $response_str = format_xml($response_str); /* Print the response*/ print "<div id=\"message\">More Backpacks requested : The purchase order number is {$responseMessage->str}</div>"; } catch (Exception $e) { if ($e instanceof WSFault) { printf("Soap Fault: %s\n", $e->Reason); } else { printf("Message = %s\n", $e->getMessage()); } } }
function ws_request($payload, $options = array(NULL)) { $payloadString = $payload; if ($payload instanceof domDocument) { $payloadString = $payload->saveXML(); } try { $requestMessage = $payload; if (!$payload instanceof WSMessage) { $requestMessage = new WSMessage($payloadString); } $client = new WSClient($options); $resMessage = $client->request($requestMessage); return $resMessage; } catch (Exception $e) { throw $e; } }
* http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ $requestPayloadString = <<<XML <ns1:echoString xmlns:ns1="http://wso2.org/wsfphp/samples"> <text>Hello World!</text> </ns1:echoString> XML; try { $client = new WSClient(array("to" => "http://localhost/samples/echo_service.php")); $header1 = new WSHeader(array("ns" => "http://test.org", "name" => "header1", "data" => "value1", "mustUnderstand" => false)); $msg = new WSMessage($requestPayloadString, array("inputHeaders" => array($header1))); $client->request($msg); $sentMsg = $client->getLastRequest(); $recvMsg = $client->getLastResponse(); echo "\nSent message \n"; echo htmlspecialchars($sentMsg); echo "\n\n Received message \n"; echo htmlspecialchars($recvMsg); } catch (Exception $e) { if ($e instanceof WSFault) { printf("Soap Fault: %s\n", $e->Reason); } else { printf("Message = %s\n", $e->getMessage()); } }
* you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ $reqPayloadString = <<<XML <ns1:echo xmlns:ns1="http://wso2.org/wsfphp/samples"><text>Hello World!</text></ns1:echo> XML; try { $rec_cert = ws_get_cert_from_file("../keys/bob_cert.cert"); $pvt_key = ws_get_key_from_file("../keys/alice_key.pem"); $reqMessage = new WSMessage($reqPayloadString, array("to" => "http://localhost/samples/security/encryption/service.php", "action" => "http://wso2.org/wsfphp/samples/echoString")); $sec_array = array("encrypt" => TRUE, "algorithmSuite" => "Basic256Rsa15", "securityTokenReference" => "IssuerSerial"); $policy = new WSPolicy(array("security" => $sec_array)); $sec_token = new WSSecurityToken(array("privateKey" => $pvt_key, "receiverCertificate" => $rec_cert)); $client = new WSClient(array("useWSA" => TRUE, "policy" => $policy, "securityToken" => $sec_token)); $resMessage = $client->request($reqMessage); printf("Response = %s \n", $resMessage->str); } catch (Exception $e) { if ($e instanceof WSFault) { printf("Soap Fault: %s\n", $e->Reason); } else { printf("Message = %s\n", $e->getMessage()); } }
} if (isset($param1) && isset($param2)) { /* echo $operation; echo $param1; echo $param2; */ $reqPayloadString = <<<XML <ns1:{$operation} xmlns:ns1="http://ws.apache.org/axis2/php/math"> <param1>{$param1}</param1> <param2>{$param2}</param2> </ns1:{$operation}> XML; try { $client = new WSClient(array("to" => $epr)); $response = $client->request($reqPayloadString); if ($response) { echo "Result : " . $response->str . ""; } } catch (Exception $e) { if ($e instanceof WSFault) { printf("Soap Fault: %s\n", $e->Reason); } else { printf("Message = %s\n", $e->getMessage()); } } } } ?>
<?php /* * Copyright 2005,2008 WSO2, Inc. http://wso2.com * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ $requestPayloadString = <<<XML <ns1:echoString xmlns:ns1="http://wso2.org/wsfphp/samples"><text>Hello World!</text></ns1:echoString> XML; try { $client = new WSClient(array("to" => "https://2ec2.wso2.org/samples/echo_service.php", "CACert" => "./resources/cacert.pem")); $responseMessage = $client->request($requestPayloadString); printf("Response = %s <br>", htmlspecialchars($responseMessage->str)); } catch (Exception $e) { if ($e instanceof WSFault) { printf("Soap Fault: %s\n", $e->Reason); } else { printf("Message = %s\n", $e->getMessage()); } }
* * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ $requestPayloadString = <<<XML <download xmlns="http://test.org"></download> XML; try { $client = new WSClient(array("to" => "http://localhost/samples/mtom/mtom_download_service.php", "useMTOM" => TRUE, "responseXOP" => TRUE)); $requestMessage = new WSMessage($requestPayloadString); $responseMessage = $client->request($requestMessage); printf("Response = %s \n", $responseMessage->str); $cid2stringMap = $responseMessage->attachments; $cid2contentMap = $responseMessage->cid2contentType; $imageName; if ($cid2stringMap && $cid2contentMap) { foreach ($cid2stringMap as $i => $value) { $f = $cid2stringMap[$i]; $contentType = $cid2contentMap[$i]; if (strcmp($contentType, "image/jpeg") == 0) { $imageName = $i . "." . "jpg"; if (stristr(PHP_OS, 'WIN')) { file_put_contents($imageName, $f); } else { file_put_contents("/tmp/" . $imageName, $f); }
echo "{$name} - <a href=\"mailto:{$email}\">{$email}</a>"; ?> </div> </div> <?php } } if ($show_comments) { $request_xml = <<<XML \t\t\t<getUsersCommentedByDuration> \t\t\t\t<startTime>{$start_time}</startTime> \t\t\t\t<endTime>{$end_time}</endTime> \t\t\t</getUsersCommentedByDuration> XML; $client = new WSClient(array("to" => SERVICE_ENDPOINT)); $response_xml = $client->request($request_xml); $doc = new DOMDocument(); $doc->loadXML($response_xml->str); $doc = new DOMDocument(); $doc->loadXML($response_xml->str); $names = $doc->getElementsByTagName("name"); $emails = $doc->getElementsByTagName("email"); $nodes = array(); for ($i = $names->length - 1; $i >= 0; $i--) { $name = $names->item($i)->nodeValue; $email = $emails->item($i)->nodeValue; if ($name == "") { continue; } ?> <div class="node">
* See the License for the specific language governing permissions and * limitations under the License. */ $requestPayloadStrings = array(); for ($i = 0; $i < 10; $i++) { $tmp = "Hello World " . "{$i}"; $requestPayloadString = <<<XML <ns1:echoString xmlns:ns1="http://ws.apache.org/axis2/c/samples"> <text>{$tmp}</text> </ns1:echoString> XML; array_push($requestPayloadStrings, $requestPayloadString); } try { $serviceClient = new WSClient(); for ($i = 0; $i < 10; $i++) { $msg = new WSMessage($requestPayloadStrings[$i], array("to" => "http://localhost/samples/echo_service.php")); $responsePayload = $serviceClient->request($msg); printf("Round %s<br>", $i); printf("--------<br>"); printf("Response = %s <br><br>", htmlspecialchars($responsePayload->str)); printf("Last Request = %s<br><br>", htmlspecialchars($serviceClient->getLastRequest())); printf("Last Response = %s<br><br>", htmlspecialchars($serviceClient->getLastResponse())); } } catch (Exception $e) { if ($e instanceof WSFault) { printf("Soap Fault : %s<br>", $e->Reason()); } else { printf("Fault Message = %s<br>", $e->getMessage()); } }
function getPortfolioFunction($inMessage) { $simplexml = new SimpleXMLElement($inMessage->str); $userid = $simplexml->param1[0]; $password = $simplexml->param2[0]; $epr = "http://localhost/samples/solutions/trader/ExchangeTrader.php"; $operation = "getPortfolio"; $doc = new DOMDocument(); if (stristr(PHP_OS, 'WIN')) { $doc = DOMDocument::load("members.xml"); } else { $doc = DOMDocument::load("/tmp/members.xml"); } $clients = $doc->getElementsByTagName("client"); foreach ($clients as $client) { $UserIDs = $client->getElementsByTagName("UserID"); $UserID = $UserIDs->item(0)->nodeValue; $passwords = $client->getElementsByTagName("Password"); $Password = $passwords->item(0)->nodeValue; if ($userid == $UserID and $password == $Password) { $Result1 = "Match"; $reqPayloadString = <<<XML <ns1:{$operation} xmlns:ns1="http://ws.apache.org/axis2/php/trader"> <param1>{$userid}</param1> <param2>{$password}</param2> </ns1:{$operation}> XML; try { $client = new WSClient(array("to" => $epr)); $response = $client->request($reqPayloadString); if ($response) { $Result = $response->str; $resPayload = <<<XML <ns1:result xmlns:ns1="http://ws.axis2.org/axis2/php/trader">{$Result}</ns1:result> XML; $returnMessage = new WSMessage($resPayload); return $returnMessage; } } catch (Exception $e) { if ($e instanceof WSFault) { print "Soap Fault:\n" . $e->Reason; } else { print "Message:\n" . $e->getMessage(); } } } } if ($Result1 == "") { $Result = "Wrong User ID or Password"; $resPayload = <<<XML <ns1:result xmlns:ns1="http://ws.axis2.org/axis2/php/trader">{$Result}</ns1:result> XML; $returnMessage = new WSMessage($resPayload); return $returnMessage; } }
</form> </body> </html> <?php if (isset($_POST['apikey'])) { $requestPayloadString = <<<XML <x:FlickrRequest xmlns:x="urn:flickr"> <method>flickr.test.echo</method> <api_key>{$apikey}</api_key> <name>{$search}</name> </x:FlickrRequest> XML; try { $flicker_client = new WSClient(array("to" => "http://localhost:8081/services/soap/")); $responseMessage = $flicker_client->request($requestPayloadString); printf("Response = %s <br>", htmlspecialchars($responseMessage->str)); } catch (Exception $e) { if ($e instanceof WSFault) { printf("Request Failed, Please enter correct flickr api key \n"); } else { printf("Message = %s\n", $e->getMessage()); } } } ?>
<test123>1 2 3 4 5 6</test123> </pro:anyElement> </pro:testDocIn> </ns1:submit> XML; try { $msg = new WSMessage($reqPayloadString, array("to" => $epr, "action" => "http://www.wso2.net/products/wsf_php/demo/submit")); $client_options = array(); $client_options["useMTOM"] = TRUE; $client_options["responseXOP"] = TRUE; if ($qosAddr) { $client_options["useWSA"] = TRUE; } $client = new WSClient($client_options); $message = $message . ">>> Sending SOAP request to " . $epr . " requesting for image " . $imageID . ".jpg<br/>"; $resMsg = $client->request($msg); $cid2str = $resMsg->attachments; $cid2cnt = $resMsg->cid2contentType; if ($cid2str) { foreach ($cid2str as $i => $value) { $f = $cid2str[$i]; file_put_contents("./client_resources/" . $imageID . ".jpg", $f); } } $message = $message . "<<< Saved image " . $imageID . ".jpg received<br/>"; $sentMsg = $client->getLastRequest(); $recvMsg = $client->getLastResponse(); echo "<strong>Showing solution blocks " . $imageID . " out of 9</strong>"; echo "<table><tr>"; for ($counter = 1; $counter <= $imageID; $counter++) { echo "<td><img src='./client_resources/" . $counter . ".jpg'/></td>";
</form> </body> </html> <?php if (isset($_POST['apikey'])) { $requestPayloadString = <<<XML <ns1:doGoogleSearch x:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="urn:GoogleSearch" xmlns:x="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http://www.w3.org/1999/XMLSchema"> <key xsi:type="xsd:string">{$apikey}</key> <q xsi:type="xsd:string">{$search}</q> <start xsi:type="xsd:int">0</start> <maxResults xsi:type="xsd:int">10</maxResults> <filter xsi:type="xsd:boolean">true</filter> <restrict xsi:type="xsd:string"></restrict> <safeSearch xsi:type="xsd:boolean">false</safeSearch> <lr xsi:type="xsd:string"></lr> <ie xsi:type="xsd:string">latin1</ie> <oe xsi:type="xsd:string">latin1</oe> </ns1:doGoogleSearch> XML; try { $client = new WSClient(array("to" => "http://api.google.com/search/beta2", "useSOAP" => "1.1")); $responsePayload = $client->request($requestPayloadString); printf("Response = %s <br/>\n", htmlspecialchars($responsePayload->str)); } catch (Exception $e) { if ($e instanceof WSFault) { printf("Please specify a correct google key"); } else { printf("Message = %s\n", $e->getMessage()); } } }
/** * Call xml web service in general * @param $method_name method name * @param $options associate array consist of options * @param $endpoint endpoint url * @return associate array consist of the response parameters */ public function call_ws($query, $method_name, array $options, $endpoint) { $xml = ""; $options["query"] = $query; $options["appid"] = $this->app_id; $keys = array_keys($options); foreach ($keys as $key) { if (empty($key)) { continue; } $value = $options[$key]; $xml .= "<{$key}>{$value}</{$key}>"; } $xml = "<{$method_name}>" . $xml . "</{$method_name}>"; $yahoo_client = new WSClient(array("to" => $endpoint, "HTTPMethod" => GET, "useSOAP" => FALSE)); $res = array(); try { $res_msg = $yahoo_client->request($xml); $res[self::RESPONSE_XML] = $res_msg->str; $res = $this->extractResponse($res); } catch (Exception $e) { if ($e instanceof WSFault) { $res[self::SOAP_FAULT] = TRUE; $res[self::SOAP_FAULT_REASON] = $e->Reason; } else { $res[self::ERROR] = TRUE; $res[self::ERROR_MSG] = $e->getMessage(); } } return $res; }