WSF/PHP with doc-lit bare WSDLs

Wednesday, April 16, 2008

You may use doc-lit bare WSDL to send a web service request with just one simple parameter in the message, like this.

<echoInt>3</echoInt>
In order to prepare this message with wsdl mode in WSF/PHP you can directly input the parameter value without instantiate any wrapper classes. Just take look at the following doc-lit bare WSDL and the corresponding WSDL-mode client to have an idea how easy it is.

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"

xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:ns0="http://wso2.org/dyn/codegen/demo"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"

xmlns:ns1="http://wso2.org/dyn/codegen/demo/xsd"
xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" targetNamespace="http://wso2.org/dyn/codegen/demo">


<wsdl:types>
<xs:schema xmlns:tns="http://wso2.org/dyn/codegen/demo"
attributeFormDefault="qualified"
elementFormDefault="qualified" targetNamespace="http://wso2.org/dyn/codegen/demo">


<xs:element name="echoInt" type="xs:int"/>
<xs:element name="echoIntResponse" type="xs:int"/>

</xs:schema>
</wsdl:types>
<wsdl:message name="echoIntRequest">
<wsdl:part name="parameters" element="ns0:echoInt"/>

</wsdl:message>
<wsdl:message name="echoIntResponse">
<wsdl:part name="parameters" element="ns0:echoIntResponse"/>

</wsdl:message>
<wsdl:portType name="EchoServicePortType">
<wsdl:operation name="echoInt">

<wsdl:input message="ns0:echoIntRequest" wsaw:Action="urn:echoInt"/>
<wsdl:output message="ns0:echoIntResponse" wsaw:Action="urn:echoIntResponse"/>

</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="EchoServiceSOAP12Binding" type="ns0:EchoServicePortType">

<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<wsdl:operation name="echoInt">

<soap12:operation soapAction="urn:echoInt" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>

</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>

</wsdl:operation>
</wsdl:binding>
<wsdl:service name="EchoService">
<wsdl:port name="EchoServiceSOAP12port_http" binding="ns0:EchoServiceSOAP12Binding">

<soap:address location="http://localhost:8080/dyn/codegen/demo/services/EchoService"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

And the client is simple as this

// the background work for create wsclient and the proxy
$client = new WSClient(array ("wsdl" =>"echo.wsdl"));

$proxy = $client->getProxy();

// you directly input the request parameter
$response = $proxy->echoInt(3);


echo $response;

So in a case where you just need to send only one parameter for the service operation, this form of messages make your web service call more efficient and more easy to implement.

No comments: