Webservice definitions

Gepost in /PHP ontwikkeling/Software op 29 Juni 2012
Deze blog is geschreven door Christiaan Schaake


This document describes how I've setup the new Mobius II website using Webservices in PHP5.



The types contain the definition of all used datatypes in the webservice. The datatypes are setup as a XSD schema. All the types are defined within the same types element. <wsdl:types>
<xsd:schema targetNamespace="" xmlns="">
<xsd:element name="DataType">
<xsd:element name="variable" type="string"/>

Types could also be imported using an external XSD. <import namespace="" location=""/>


Every message describes a message without direction (abstract). A message has an unique name and a part refering to a datatype defined in the types element. <wsdl:message name="AbstractInputMessage">
<wsdl:part name="body" element="xsd1:DataType"/>
A message does not have to use a element attribute refering to a datatype, but can also use a type attribute to define the message directly. Every message used by the webservice must be defined in a message element. This includes all incoming, outgoing and fault messages.


The portType is a set of abstract operations where each operation referes to an input and an output message, and optionally a fault message. <wsdl:portType name="SamplePortType">
<wsdl:operation name="MyFunction">
<wsdl:input message="tns:AbstractInputMessage"/>
<wsdl:output message="tns:AbstractOutputMessage"/>
<wsdl:fault message="tns:AbstractFaultMessage"/>
The operation wihtin the portType defines an action supported by the service.
There are 4 types of operations that a webservice can be define for:

  • One-way - Only uses an input message
  • Request-response - Uses both an input and an output message, optionally a fault message
  • Solicit-response - Uses both an output and an input message, but the initiator is the webservice itself. The process is started by the webservice sending the output message first.
  • Notification - Only an output message is used. The webservice send a message out and does not expect a response.
The One-way and the Request-response are the most commonly used ones. There is no way to set the type of operation, but this is simply defined by the use and the order of messages.


<wsdl:binding name="SampleBinding" type="tns:SamplePortType">
<soap:binding style="document" transport=""/>
<wsdl:operation name="MyFunction">
<soap:body use="literal"/>
<soap:body use="literal"/>
<wsdl:fault name="FaultMessage">
<soap:body name="FaultMessage" use="literal"/>
The binding also includes SOAP bindings, which are the bindings (connections) to the SOAP messages. The first soap binding sets the type of the soap binding, which is in the example the default document style. The document style expects a SOAP document as input/output and/or fault messages. Another option is RFC style. This style expects parameters and return values.

The soap:body binding refere to the messages used for input/output and fault. In this example the binding for the message is set to literal. Another option is encoded.

For the fault message the name must be specified and the message must consist of a single part. Since the fault message cannot be a parameter, it's always assumed to be a document style.


<wsdl:service name="SampleService">
<wsdl:port name="SamplePort" binding="tns:SampleBinding">
<soap:address location=""/>
The soap binding address specifies the address of the webservice. This is where the webservice is called and the actual program behind the webservice lives.

Deze blog is getagd als Webservice WSDL