views:

366

answers:

1

I'm trying to consume a hello world AXIS2 SOAP web service using a PHP client. The Java class is written in Netbeans and the AXIS2 aar file is generated using the Netbeans AXIS2 plugin.

You've all seen it before but here's the java class:

public class SOAPHello {    
    public String sayHello(String username) {
        return "Hello, "+username;
    }  
}

The wsdl genereated by AXIS2 seems to wrap all the parameters so that when I consume the service i have to use a crazy PHP script like this:

$client = new SoapClient("http://myhost:8080/axis2/services/SOAPHello?wsdl");
$parameters["username"] = "Dave";
$response = $client->sayHello($parameters)->return;
echo $response."!";

When all I really want to do is

   echo $client->sayHello("Dave")."!";

My question is two-fold: why is this happening? and what can I do to stop it? :)

Here's are the types, message and porttype sections of the generated wsdl:

<wsdl:types>
   <xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://soap.axis2.myhost.co.uk"&gt;
      <xs:element name="sayHello">
         <xs:complexType>
            <xs:sequence>
               <xs:element minOccurs="0" name="username" nillable="true" type="xs:string"/>
            </xs:sequence>
         </xs:complexType>
      </xs:element>
      <xs:element name="sayHelloResponse">
         <xs:complexType>
            <xs:sequence>
               <xs:element minOccurs="0" name="return" nillable="true" type="xs:string"/>
            </xs:sequence>
         </xs:complexType>
      </xs:element>
   </xs:schema>
</wsdl:types>

<wsdl:message name="sayHelloRequest">
   <wsdl:part name="parameters" element="ns:sayHello"/>
</wsdl:message>    
<wsdl:message name="sayHelloResponse">
   <wsdl:part name="parameters" element="ns:sayHelloResponse"/>
</wsdl:message>

<wsdl:portType name="SOAPHelloPortType">
   <wsdl:operation name="sayHello">
      <wsdl:input message="ns:sayHelloRequest" wsaw:Action="urn:sayHello"/>
      <wsdl:output message="ns:sayHelloResponse" wsaw:Action="urn:sayHelloResponse"/>
   </wsdl:operation>
</wsdl:portType>
A: 

I was searching for the same question and did not find a solution. It seemes like this is some kind of axis2 philosophy to generate this kind of crappy interface which i find very unreadable. But i think for the most purposes you would just accept it. If you don't like this and use the webservice a lot in your application, then write a wrapper class like this:

class soapHelloWebservice {
   public function sayHello($username) {
      $client = new SoapClient("http://myhost:8080/axis2/services/SOAPHello?wsdl");
      $parameters["username"] = $username;
      return $client->sayHello($parameters)->return;
   } 
}
Jeff