Showing posts with label WSMessage. Show all posts
Showing posts with label WSMessage. Show all posts

5 Facts About WS-Addressing Action in WSF/PHP

Wednesday, November 26, 2008

WS-Addressing Action is used by web services to dispatch the operation for an incoming request SOAP message. This blog "5 Facts About WS-Addressing Action" present you some facts about WSF/PHP API for WS-Addressing.

Introduction to reliable messaging part 3

Monday, November 10, 2008

In this blog post, we will look at how you can send multiple application messages within a single sequence reliably using

WSClient API.  For this purpose WSClient has an option named willContinueSequence. If you intend to send only a since application message within your reliable sequence, then you do not need to touch this option. However, when sending multiple application messages, you need to use it as follows.

1. When sending the first message, set willContinueSequence=TRUE in WSClient.

2. Send your application messages by using WSMessage object.

3. When you want to send the final application message to be sent within the reliable sequence, set the option lastMessage to true.

Here is a code example demonstrating this.

Step 1. First create an application message.

$requestPayloadString = <<<XML
    <ns1:pingString xmlns:ns1="http://wso2.org/wsfphp/samples/reliable">
        <text>Hello World!</text>
    </ns1:pingString>
XML;

Step 2. Create a WSClient object with willContinueSequence option set to TRUE

$client = new WSClient(array( "reliable" => TRUE, "useWSA" => TRUE, "willContinueSequence" => TRUE));

Step 3. Create and Send WSMessage objects containing application messages.

$message = new WSMessage($requestPayloadString,
           array( "to" => "http://localhost/samples/reliable/ping_service_rm.php",
                  "action" => http://wso2.org/wsfphp/samples/pingString));

$client->send($message);

$message1 = new WSMessage($requestPayloadString,
            array( "to" => "http://localhost/samples/reliable/ping_service_rm.php",
                   "action" => "http://wso2.org/wsfphp/samples/pingString"));

    $client->send($message1);

Step 4. When you want to send the last application message, set the option lastMessage to true in WSMessage object.

$message2 = new WSMessage($requestPayloadString,
    array( "to" => "http://localhost/samples/reliable/ping_service_rm.php",
           "action" => "http://wso2.org/wsfphp/samples/pingString",
           "lastMessage" => TRUE));

$client->send($message2);

Note that this is a ping service and hence the use of the method send in WSClient. You can similarly use request method as well.

"opParams" option for WSService

Tuesday, May 6, 2008

The option "opParams" is an optional parameter to the WSService. If you set opParams to WSMESSAGE the service function would be like this,

/* this is the service function */
function echoFunction($inMessage /* with the type of WSMessage */) {

$outMessage = new WSMessage($inMessage->str);


return $outMessage; /* with the type of WSMessage */
}

$operations = array("echoString" => "echoFunction");


$opParams = array("echoFunction" => "WSMESSAGE");
/* WSMESSAGE is the default value for this situation */

$service = new WSService(array(


"opParams" => $opParams,

"operations" => $operations))

Note that when you provide WSMESSAGE to the "opParams", the service operation parameters(both input and output) are of the type WSMessage.
Now say we put "MIXED" in there like the one in following
/* this is the service function */
function echoFunction($inMessage /* with the type of string */) {

$outMessage = $inMessage;

return $outMessage; /* with the type of String */
}

$operations = array("echoString" => "echoFunction");


$opParams = array("echoFunction" => "MIXED");
/* MIXED is the default value for this situation */

$service = new WSService(array(

"wsdl" => "http://localhost/echostring.wsdl",
"opParams" => $opParams,

"operations" => $operations))

Here note the difference in the service operation. Now the argument types are strings. This types are defined in the wsdl which is provided as an argument to the WSService.

So it is clear

When "wsdl" is provided the opParams are default to "MIXED",
otherwise it is default to "WSMESSAGE".

So you don't need to provide the opParams option explicitly in both above cases.

Where to set your options?.. in WSClient or in WSMessage?

Wednesday, January 23, 2008

If you are familiar with WSF/PHP web service API, you may find that you can set your options in different level in your code . For an example when you are writing a web service client, you can set the same options set in the WSClient constructor or in the WSMessage constructor.

I wrote a blog with my ideas on how to select the right place to set the options in order to have well designed and efficient web service client.