Home » Php » How to use XSD files with PHP SOAP server/client?

How to use XSD files with PHP SOAP server/client?

Posted by: admin August 13, 2018 Leave a comment

Questions:

I’m new to SOAP and I’ve been tasked with creating a SOAP server that receives messages that are a part of the papiNet standard.

Sample XSD:
http://www.papinet.org/fileadmin/user_upload/v2r40/DeliveryMessageV2R40.xsd
Sample message:
https://gist.github.com/tostercx/016a387848732d057c7674e08f9a8149

The standard only defines XSD files.

I’ve set up a test Zend-SOAP server following this: https://dev.to/dopitz/implementing-a-soap-api-with-php-a3n

How would I transfer objects that are specified in the XSD? I’ve seen people importing the XSD in a manually created WSDL file: https://stackoverflow.com/a/12125913

I managed to bodge together a WSDL from the auto generated methods and the above importing example.

<?xml version="1.0" encoding="UTF-8"?>
<definitions
    ...
    xmlns:pn="http://www.papinet.org/v2r40"
    ...
    >
    <types>
        <xsd:schema targetNamespace="http://test.loc/api/soap">
            <xsd:import namespace="http://www.papinet.org/v2r40" schemaLocation="http://www.papinet.org/fileadmin/user_upload/v2r40/DeliveryMessageV2R40.xsd" />
            ...
        </xsd:schema>
    </types>
    <portType name="SoapEndpointPort">
        <operation name="storeDeliveryMessage">
            <documentation>Store and process a DeliveryMessage</documentation>
            <input message="tns:storeDeliveryMessageIn" />
            <output message="tns:storeDeliveryMessageOut" />
        </operation>
    </portType>
    <binding name="SoapEndpointBinding" type="tns:SoapEndpointPort">
        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
        <operation name="storeDeliveryMessage">
            <soap:operation soapAction="http://test.loc/api/soap#storeDeliveryMessage" />
            <input>
                <soap:body use="literal" />
            </input>
            <output>
                <soap:body use="literal" />
            </output>
        </operation>
    </binding>
    ...
    <message name="storeDeliveryMessageIn">
        <part name="parameters" element="pn:DeliveryMessage" />
    </message>
</definitions>

I have no idea if I’m on the right track. The DeliveryMessage type now appears in getTypes of a Zend-SOAP client. How would the client use the type information to construct the message body? How would a server receive the object?

Answers: