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">
<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"/>
开发者_C百科 <wsdl:output message="ns:sayHelloResponse" wsaw:Action="urn:sayHelloResponse"/>
</wsdl:operation>
</wsdl:portType>
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;
}
}
This is called the document/literal wrapped pattern. See this document and this one.
Basically, when using the document/literal request encoding, the client doesn't necessarily send the name of the web service operation that it is calling. The server has to figure it out from the request object. To ensure that the server can do that, a different request object is defined for each web service operation.
When generating the client code using the WSDL2JAVA command-line tool (bundled with Axis2), add parameter '-uw' to unwrap the parameter, i.e. instead of setting the parameters in a bean, you would just send them as method parameters.
We use this all the time in our project.
精彩评论