Beispiel #1
0
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());
        }
    }
}
Beispiel #2
0
 * 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());
    }
}
 * 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());
    }
}