HomerPlata
HomerPlata

Reputation: 1797

Problems with XML structure of SOAP request in PHP

I am trying to mock a SOAP request in PHP, and once it is received by my endpoint it is coming out like:

<?xml version="1.0" encoding="UTF-8"?>
<Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns2="http://xml.apache.org/xml-soap" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    <Body>
        <Callback>
            <param0 xsi:type="ns2:Map">
                <item>
                    <key xsi:type="xsd:string">ProposalID</key>
                    <value xsi:type="xsd:int">XXXXXXXX</value>
                </item>
                <item>
                    <key xsi:type="xsd:string">ProposalStatus</key>
                    <value xsi:type="ns2:Map">
                        <item>
                            <key xsi:type="xsd:string">IsParked</key>
                            <value xsi:type="xsd:boolean">false</value>
                        </item>
                        <item>
                            <key xsi:type="xsd:string">Status</key>
                            <value xsi:type="xsd:string">Accepted</value>
                        </item>
                    </value>
                </item>
                <item>
                    <key xsi:type="xsd:string">CustomerAddress</key>
                    <value xsi:type="SOAP-ENC:Struct">
                        <HouseNumber xsi:type="xsd:int">XXXXXXXX</HouseNumber>
                        <HouseName xsi:nil="true" />
                        <Flat xsi:nil="true" />
                        <Street xsi:type="xsd:string">XXXXXXXX</Street>
                        <District xsi:type="xsd:string">XXXXXXXX</District>
                        <Town xsi:type="xsd:string">XXXXXXXX</Town>
                        <County xsi:type="xsd:string">XXXXXXXX</County>
                        <Postcode xsi:type="xsd:string">XXXXXXXX</Postcode>
                    </value>
                </item>
                <item>
                    <key xsi:type="xsd:string">Snags</key>
                    <value xsi:nil="true" />
                </item>
                <item>
                    <key xsi:type="xsd:string">ChecklistConditions</key>
                    <value xsi:type="ns2:Map">
                        <item>
                            <key xsi:type="xsd:string">ChecklistConditions</key>
                            <value SOAP-ENC:arrayType="SOAP-ENC:Struct[3]" xsi:type="SOAP-ENC:Array">
                                <item xsi:type="SOAP-ENC:Struct">
                                    <Type xsi:type="xsd:string">ID Verified</Type>
                                    <Status xsi:type="xsd:string">Please select</Status>
                                    <Satisfied xsi:type="xsd:boolean">false</Satisfied>
                                    <SatisfiedOn xsi:nil="true" />
                                </item>
                                <item xsi:type="SOAP-ENC:Struct">
                                    <Type xsi:type="xsd:string">Goods Quantity</Type>
                                    <Status xsi:type="xsd:string">Please select</Status>
                                    <Satisfied xsi:type="xsd:boolean">false</Satisfied>
                                    <SatisfiedOn xsi:nil="true" />
                                </item>
                                <item xsi:type="SOAP-ENC:Struct">
                                    <Type xsi:type="xsd:string">Delivery Notification</Type>
                                    <Status xsi:type="xsd:string">Please select</Status>
                                    <Satisfied xsi:type="xsd:boolean">false</Satisfied>
                                    <SatisfiedOn xsi:nil="true" />
                                </item>
                            </value>
                        </item>
                    </value>
                </item>
                <item>
                    <key xsi:type="xsd:string">ClientReference</key>
                    <value xsi:type="xsd:string">XXXXXXXX</value>
                </item>
            </param0>
        </Callback>
    </Body>
</Envelope>

Whereas the proper request looks like this (with proper formatting of elements, instead of key/value formatting inside item tags etc) :

<?xml version="1.0" encoding="utf-8"?>
<Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <Body>
        <Callback>
            <ProposalID>XXXXXXXX</ProposalID>
            <ProposalStatus IsParked="false">
                <Status>Accepted</Status>
            </ProposalStatus>
            <CustomerAddress>
                <HouseNumber>XXXXXXXX</HouseNumber>
                <HouseName>XXXXXXXX</HouseName>
                <Flat />
                <Street>XXXXXXXX</Street>
                <District />
                <Town>XXXXXXXX</Town>
                <County>XXXXXXXX</County>
                <Postcode>XXXXXXXX</Postcode>
            </CustomerAddress>
            <ChecklistConditions>
                <ChecklistCondition Type="Delivery Note">
                    <Status>Not Received</Status>
                    <Satisfied>false</Satisfied>
                </ChecklistCondition>
                <ChecklistCondition Type="CCA Documents Received">
                    <Status>Not Received</Status>
                    <Satisfied>false</Satisfied>
                </ChecklistCondition>
            </ChecklistConditions>
            <ClientReference>XXXXXXXX</ClientReference>
        </Callback>
    </Body>
</Envelope>

I am generating the mock request via the following PHP code:

public function generateMockCallbackArray($ClientReference, $ProposalID, $status)
{
    // first, make any required constituent objects
    $ProposalStatus = new ProposalStatus(false, $status);
    $CustomerAddress = new Address("XXXXXXXX", NULL, NULL, "XXXXXXXX", "XXXXXXXX", "XXXXXXXX", "XXXXXXXX", "XXXXXXXX");
    $Snags = NULL;
    $ChecklistConditions = new ChecklistConditions(
        array(
            new ChecklistCondition("ID Verified", "Please select", false, NULL),
            new ChecklistCondition("Goods Quantity", "Please select", false, NULL),
            new ChecklistCondition("Delivery Notification", "Please select", false, NULL)
        )
    );

    // build into Callback object and return as array
    $Callback = new Callback($ProposalID, $ProposalStatus, $CustomerAddress, $Snags, $ChecklistConditions, $ClientReference);

    return [
        "Callback" => $Callback->toArray()
    ];
}

Can anyone see where I'm going wrong? If I can make alterations to the generateMockCallbackArray() method, that would be ideal. Thanks.

Upvotes: 0

Views: 733

Answers (1)

Mika&#235;l DELSOL
Mika&#235;l DELSOL

Reputation: 760

You should use a WSDL to php generator to stop wondering how to structure your request.

Try the PackageGenerator project and let me know then.

Upvotes: 1

Related Questions