Вызов службы SOAP (XML) с помощью PHP - PullRequest
0 голосов
/ 16 октября 2018

У меня есть веб-сервис поставщика, доступный в SOAP / XML, и я пытаюсь отправить ему запросы с моего веб-сайта, работающего на PHP.

WSDL можно найти здесь: https://www.gateway.uat.asic.gov.au/gateway/ExternalSearchNniNamePortV3?wsdl

Пример запроса для вызова этого WS будет:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<uri:request xmlns:uri="uri:v3.external.search.nni.name.asic.gov.au" oas:Id="Example-1">
    <uri1:businessDocumentHeader xmlns:uri1="uri:business.document.header.types.asic.gov.au">
        <uri1:messageType>searchNniName</uri1:messageType>
        <uri1:messageReferenceNumber>[messageReferenceNumber]</uri1:messageReferenceNumber>
        <uri1:messageVersion>3</uri1:messageVersion>
        <uri1:senderId>[senderId]</uri1:senderId>
        <uri1:senderType>REGA</uri1:senderType>
    </uri1:businessDocumentHeader>
    <uri:businessDocumentBody>
        <uri4:searchType xmlns:uri4="uri:nni.types.asic.gov.au">S</uri4:searchType>
        <uri4:searchScope xmlns:uri4="uri:nni.types.asic.gov.au">2</uri4:searchScope>
        <uri4:organisation xmlns:uri4="uri:nni.types.asic.gov.au">
            <uri4:name>ARROW RESOURCES MANAGEMENT PTY. LIMITED</uri4:name>
        </uri4:organisation>
        <uri4:maxResult xmlns:uri4="uri:nni.types.asic.gov.au">1</uri4:maxResult>
    </uri:businessDocumentBody>
</uri:request>

Мой PHP-код пока выглядит следующим образом:

$wsdl = "https://www.gateway.uat.asic.gov.au/gateway/ExternalSearchNniNamePortV3?wsdl";
        //$client = new SoapClient($wsdl);

        try {

            $soapClientOptions = array(
                'cache_wsdl' => 0,
                'trace' => 1,
                'login' => '***',
                'password' => '***',
                'stream_context' => stream_context_create(array(
                    'ssl' => array(
                        'verify_peer' => false,
                        'verify_peer_name' => false,
                        'allow_self_signed' => true,
                    ),
                )),
            );
            $client = new SoapClient($wsdl, $soapClientOptions);

            $xml = new XMLWriter();
            $xml->openMemory();
            $xml->startElementNS('uri', "request", 'uri:v3.external.search.nni.name.asic.gov.au');
            $xml->writeAttributeNS(
                'oas',
                'Id',
                'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd',
                'Example-1'
              );
                $xml->startElementNS('uri1', "businessDocumentHeader", "uri:business.document.header.types.asic.gov.au");
                    $xml->startElementNS('uri1', 'messageType', null);
                        $xml->Text("searchNniName");
                    $xml->endElement();
                    $xml->startElementNS('uri1', 'messageVersion', null);
                        $xml->Text("3");
                    $xml->endElement();
                    $xml->startElementNS('uri1', 'senderId', null);
                        $xml->Text("0000123");
                    $xml->endElement();
                    $xml->startElementNS('uri1', 'senderType', null);
                        $xml->Text("REGA");
                    $xml->endElement();
                $xml->endElement();
                $xml->startElementNS('uri', "businessDocumentBody", null);
                    $xml->startElementNS('uri4', 'searchType', "uri:nni.types.asic.gov.au");
                        $xml->Text("searchNniName");
                    $xml->endElement();
                    $xml->startElementNS('uri4', 'searchScope', "uri:nni.types.asic.gov.au");
                        $xml->Text("3");
                    $xml->endElement();
                    $xml->startElementNS('uri4', 'organization', "uri:nni.types.asic.gov.au");
                        $xml->startElementNS('uri4', 'name', null);
                            $xml->Text("Caleidro");
                        $xml->endElement();
                    $xml->endElement();
                    $xml->startElementNS('uri4', 'maxResult', "uri:nni.types.asic.gov.au");
                        $xml->Text("1");
                    $xml->endElement();
                $xml->endElement();
            $xml->endElement();

            //Convert it to a valid SoapVar
            $args = new SoapVar($xml->outputMemory(), XSD_ANYXML);

            $request_param = array(
                "request" => array(
                    "businessDocumentHeader" => array(
                        "messageType" => "searchNniName",
                        //"messageReferenceNumber" => "???",
                        "messageVersion" => 3,
                        "senderId" => "0000123",
                        "senderType" => "REGA",
                    ),
                    "businessDocumentBody" => array(
                        "searchType" => "S", //for the Standard search where all matching entries will be returned
                        "searchScope" => "A", //search for all identities
                        "organisation" => array(
                            "name" => "Caleidro",
                        ),
                        "maxResult" => 1,
                    )
                )
            );

            $response_param = $client->externalSearchNniName(array($args));
            //$xml = simplexml_load_string($response_param);
            //$result = $response_param->AddResult;
            exit('My response is ' . print_r($response_param));
        } catch (Exception $e) {

            echo "Exception Error!";
            exit($e->getMessage());

        }

}

Это, к сожалению,выдает исключение со следующим сообщением: SOAP-ERROR: Encoding: object has no 'businessDocumentHeader' property

Мне кажется, что я неправильно создаю XMLWriter.Но я не могу найти проблему.

Любая помощь будет оценена.Спасибо

РЕДАКТИРОВАТЬ

Я печатаю ошибку с дополнительной информацией

exit('ERROR ' . $e->getMessage() . ' ====== ' . $client->__getLastRequest());

Сообщение теперь:

Fatal error: SOAP-ERROR: Encoding: object has no 'businessDocumentHeader' property in /home/caleidro/public_html/wp-content/plugins/insert-php/includes/class.plugin.php(184) : eval()'d code on line 90

Действительно, похоже, что я неправильно сочиняю свой XMLWritter

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...