public static function register($name, $password, $first, $last, $email, $address, $country, $postal_code) { $client = new WSClient(array("wsdl" => "Calendar.wsdl", "useSOAP" => 1.2, "to" => "http://localhost/samples/solutions/calendar/CalendarService.php")); $proxy = $client->getProxy(); $return_val = $proxy->register(array("username" => $name, "password" => $password, "first_name" => $first, "last_name" => $last, "email" => $email, "address" => $address, "country" => $country, "postal_code" => $postal_code)); return $return_val; }
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_send($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); $client->send($requestMessage); return; } catch (Exception $e) { throw $e; } }
/** * Construct the AmazonClient * @param $amazon_key Amazon App Key */ public function __construct($amazon_key, $method) { if ($method == "SOAP" || $method == "soap") { parent::__construct(array("to" => self::AMAZON_SOAP_ENDPOINT, "useSOAP" => "1.1", "action" => "http://soap.amazon.com")); $this->is_soap = TRUE; } else { parent::__construct(array("to" => self::AMAZON_REST_ENDPOINT, "HTTPMethod" => "GET", "useSOAP" => FALSE)); $this->is_soap = FALSE; } $this->amazon_key = $amazon_key; }
function connect($async = false) { if (!parent::connect($async)) { return false; } while ($this->socket_id === "") { if ($this->readEvent() === false) { return false; } } return true; }
// The "value" represents the element 'images' value.. public $value; } class setPerson { public $param0; } class setPersonResponse { public $return; } // define the class map $class_map = array("anyType" => "anyType", "getPerson" => "getPerson", "getPersonResponse" => "getPersonResponse", "Person" => "Person", "base64Binary" => "base64Binary", "setPerson" => "setPerson", "setPersonResponse" => "setPersonResponse"); try { // create client in WSDL mode $client = new WSClient(array("wsdl" => "http://localhost/samples/wsdl_mode/MimeService.php?wsdl", "to" => "http://localhost/samples/wsdl_mode/MimeService.php", "classmap" => $class_map, "useMTOM" => FALSE)); // get proxy object reference form client $proxy = $client->getProxy(); // create input object and set values $input = new getPerson(); $input->param0 = 3; // call the operation $response = $proxy->getPerson($input); echo "Received Person Object values "; var_dump($response); $input = new setPerson(); $ppl = new Person(); $ppl->age = 3; $bin1 = new base64Binary(); $bin1->contentType = "image/jpeg"; $bin1->value = "xxxxx";
* 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 <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 {
* 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. */ $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()); }
/** * Construct the FlickrClient */ public function __construct($api_key) { parent::__construct(array("to" => self::ENDPOINT)); $this->api_key = $api_key; }
public static function register($name, $password, $first, $last, $email, $address, $country, $postal_code) { // we need to create a static function for the register, since it doesn't need any signed in $client = new WSClient(array("wsdl" => "Calendar.wsdl", "classmap" => CalendarClient::getClassmap(), "to" => self::ENDPOINT)); $proxy = $client->getProxy(); $return_val = $proxy->register(array("username" => $name, "password" => $password, "firstName" => $first, "lastName" => $last, "email" => $email, "address" => $address, "country" => $country, "postalCode" => $postal_code)); return $return_val; }
public static function getNodesByDuration($input) { try { //TODO: fill $input with (data type: anyType) data to match your business logic // call the operation // create a private client and proxy in WSDL mode $client = new WSClient(array("wsdl" => "DrupalAPI.wsdl", "classmap" => DrupalAPIClient::$class_map)); $proxy = $client->getProxy(); $response = $proxy->getNodesByDuration($input); //TODO: Implement business logic to consume $response, which is of type getNodesResponse return $response; } catch (Exception $e) { // in case of an error, process the fault 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()); } }
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; } }
<input style="margin-left:200px;" type="submit" value="submit" name="submit"/> </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()); } } } ?>
</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; }
* 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()); } }
<?php 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; } ?>
<?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:notifyString xmlns:ns1="http://wso2.org/wsfphp/samples"><text>Hello World!</text></ns1:notifyString> XML; try { $client = new WSClient(array("to" => "http://localhost/samples/notify_service.php")); $client->send($requestPayloadString); printf("Request sent to endpoint\n"); } catch (Exception $e) { if ($e instanceof WSFault) { printf("Soap Fault: %s\n", $e->Reason); } else { printf("Message = %s\n", $e->getMessage()); } }
$operation = $_GET['operation']; } 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()); } } } } ?>
#!/usr/bin/php <?php include "wsframe.class.php"; include "wsclient.class.php"; $ws = new WSClient('echo.websocket.org', '/', false); //var_dump($ws); if ($ws->connect(true)) { echo "Websocket connected\n"; } //var_dump($ws); //var_dump($ws->getMetadata()); for (;;) { $text = "Text from " . date("Y-m-d H:i:s"); echo "Sending text '{$text}'\n"; if (!$ws->send(WS_FRAME_TEXT, $text, 1)) { die($ws->errstr); } do { echo "."; $rv = $ws->read(); if ($rv === false) { die($ws->errstr); } } while ($rv == 0); echo "\n"; if ($rv > 0) { $frame = $ws->getFrame(); echo "Received text '" . $frame->payload . "'\n"; } sleep(1); }
* * 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()); }
/** * Construct the AmazonClient * @param $amazon_key Amazon App Key */ public function __construct($amazon_key) { parent::__construct(array("to" => self::AMAZON_ENDPOINT, "HTTPMethod" => GET, "useSOAP" => FALSE)); $this->amazon_key = $amazon_key; }