Calling NetBeans 6.1′s SecureCalculatorApp example web service using WSO2 WSF/PHP

I have been working to get WSO2 WSF/PHP 2.0.0 to work with the SecureCalculatorApp example web service provided with NetBeans 6.1. I want to be able to call a secure web service created with NetBeans 6.1′s user interface from an application written in PHP. SecureCalculatorApp example provides a really good starting point for a simple interoperability test.

NetBeans’s user interface for managing the security etc. settings of a web service is pretty simple and lacks a lot of the control for the configuration that is implicitly created by NB. This is unfortunate, because NB seems to create pretty advanced/complex configurations even there would not be need for such.

In WSF/PHP the security configuration of a web service (from the client viewpoint) can be defined by using WSPolicy class. An instance of this class may be given as a parameter to WSClient, which will then use the configuration when calling the web service. WSPolicy object can be instantiated by two methods: either by defining the settings as an array of values or by feeding in a separate policy XML file. The array method does not allow managing all of the supported settings and can only be used in very simple cases.

Because of the restrictions of the array method, it is necessary to use a separate policy XML file to describe the configuration when calling a secure web service created using NB. The policy XML file can be manually formed by studying the web service’s WSDL, which in fact, contains all the necessary information inside its policy elements. Because the policy elements can’t just simple be copied and pasted to a separate file, it is usually easier to take an existing policy file as a template and then modify it to fulfill the requirements of the service based on the WSDL.

After creating a simple PHP script and the necessary policy file in XML, I was able to call the service as expected. Here are the files:

Unfortunately, I didn’t get WSDL mode working. The problem seems to be that even the useWSA value is set to true on WSClient, addressing is not used in the WSDL mode. This prevents using WSDL mode with web services configured alike with NB 6.1′s SecureCalculatorApp.

Comments

  1. Hi Pauli,
    You can get the addressing working on wsdl mode if the addressing information are available in the wsdl. If you can edit the wsdl, you better try out adding wsaw:Action to the portType/operation/input and output like this (snippet from http://labs.wso2.org/wsf/php/example.xml),

    (you need to declare xmlns:wsaw=”http://www.w3.org/2006/05/addressing/wsdl” at the top)

    Thanks
    Dimuthu
    http://www.dimuthu.org

  2. boro says:

    Thanks Dimuthu for the tip! I actually got bored with WSF/PHP in the end since it was so tricky to get working and it didn’t really handle errors well enough. I decided to use Java 6 on the client side too, which proved to be a good choice.

  3. djspite says:

    This was a big help, wish I’d found this page a few hours ago … if anyone else is looking like I was, here’s some keywords:

    Username Authentication with Symmetric Key glassfishesb wso2 php ws-security

    Also, I was able to trim down the code slightly.. you don’t need the client cert and key so you end up with something like this:

    $security_token = new WSSecurityToken(array(“user” => “wsitUser”,
    “password” => “changeit”,
    “passwordType” => “PlainText”,
    “receiverCertificate” => $server_cert));

    And wsdl is apparently working now.

Submit a Comment

You must be logged in to post a comment.

*