$client = new SoapClient("http://soap.m4u.com.au/?wsdl", array("trace" => 1));
$params = array(

      "authentication" => array(
        "userId" => "user",
        "password" => "pass"
      ),
      "requestBody" => array(
        "messages" => array(
            "message" => array(
                "recipients" => array( "recipient" => array("1" => "9799996899") ),
                "content" => "Message Content"
            )
        )
      )

);

$response = $client->__soapCall("sendMessages", array($params));

But I am getting following error

Fatal error: Uncaught SoapFault exception: [SOAP-ENV:Client] The request is either not well-formed or is not valid against the relevant schema.

I need the request format like below.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://xml.m4u.com.au/2009">
<soapenv:Header/>
<soapenv:Body>
    <ns:sendMessages>
        <ns:authentication>
            <ns:userId>Username</ns:userId>
            <ns:password>Password</ns:password>
        </ns:authentication>
        <ns:requestBody>
            <ns:messages>
                <ns:message format="SMS" sequenceNumber="1">
                    <ns:recipients>
                        <ns:recipient uid="1">61400000001</ns:recipient>
                        <ns:recipient uid="2">61400000002</ns:recipient>
                    </ns:recipients>
                <ns:content>Message Content</ns:content>
                </ns:message>
            </ns:messages>
        </ns:requestBody>
    </ns:sendMessages>
</soapenv:Body>
</soapenv:Envelope>

How I can achieve this, please help.

1

There are 1 answers

0
Rob Baillie On

You've got a tricky one there.

I haven't got the time to solve it fully, but it looks like the format of the WSDL means that SoapClient MUST provide an object structure.

I can't think off the top of my head how to represent the multiple node entries without using arrays (which see to then get decomposed before being sent)

I know it's not a complete solution, but I think this is moving along the right lines (as a proof of concept)

Note the use of __getLastRequest against the SoapClient to retrieve exactly what you are sending to the server. It's very useful...

<?php

class authentication {

    public $userId;
    public $password;

    function __construct( $userId, $password ) {
        $this->userId   = $userId;
        $this->password = $password;
    }
}

class message {

    public $recipients;
    public $content;

    function __construct( $recipients, $content ) {
        $this->recipients = $recipients;
        $this->content    = $content;
    }
}

class requestBody {

    public $messages;

    function __construct( $messages ) {
        $this->messages = $messages;
    }
}

$client = new SoapClient("http://soap.m4u.com.au/?wsdl", array("trace" => 1));
$params = array(
      "authentication" => new authentication( 'user', 'pass' ),
      "requestBody"    => new requestBody( array( new message( array( '1' => '61400000001' )
                                                             , 'message content' )
                                                )
                                         )
      );

try {
    $response = $client->sendMessages( $params );
} catch(SoapFault $e) {
    file_put_contents( 'request.xml', $client->__getLastRequest() );
    throw $e;
}


?>

I think your best bet is to get in touch with the service supplier to find if anyone else has connected via PHP.

Sorry I can't be of more help - I hope this is useful!