Schaake.nu

Webservice definitions

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

Preface

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

WSDL File

types

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="http://schaake.nu/example.xsd" xmlns="http://www.w3.org/2000/10/XMLSchema">
<xsd:element name="DataType">
<xsd:complexType>
<xsd:all>
<xsd:element name="variable" type="string"/>
</xsd:all>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</wsdl:type>

Types could also be imported using an external XSD. <import namespace="http://example.com/stockquote/schemas" location="http://example.com/stockquote/stockquote.xsd"/>

message

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"/>
<wsdl:message>
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.

portType

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"/>
</wsdl:operation>
</wsdl:portType>
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.

binding

<wsdl:binding name="SampleBinding" type="tns:SamplePortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="MyFunction">
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
<wsdl:fault name="FaultMessage">
<soap:body name="FaultMessage" use="literal"/>
</wsdl:fault>
</wsdl:operation>
</wsdl:binding>
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.

service

<wsdl:service name="SampleService">
<wsdl:port name="SamplePort" binding="tns:SampleBinding">
<soap:address location="http://schaake.nu/webservices/sample.php"/>
</wsdl:port>
</wsdl:service>
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

Google
facebook