PHP Soap - Не могу запросить с сервера (WSDL)

Я очень новичок в сервисе SOAP.

Я получил эту ошибку для реализации в PHP.

Серверу не удалось обработать запрос. ---> Ссылка на объект не установлена ​​на экземпляр объекта.

Код: мыльный конверт (я нашел его с помощью Почтальона)

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
  xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
  xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Header>
    <wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
      <wsse:UsernameToken wsu:Id="UsernameToken-1" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
        <wsse:Username>username</wsse:Username>
        <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">password</wsse:Password>
      </wsse:UsernameToken>
    </wsse:Security>
  </soapenv:Header>
  <soap:Body>
    <GetDataXMLbyID xmlns="http://tempuri.org/">
      <id>3133717</id>
      <datatypes>
        <AgentName>TEST</AgentName>
      </datatypes>
    </GetDataXMLbyID>
  </soap:Body>
</soap:Envelope>

Код: PHP

<?php  

class WsseAuthHeader extends SoapHeader {

    private $wss_ns = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';

    function __construct($user, $pass, $ns = null) {
        if ($ns) {
            $this->wss_ns = $ns;
        }

        $auth = new stdClass();
        $auth->Username = new SoapVar($user, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns);
        $auth->Password = new SoapVar($pass, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns);

        $username_token = new stdClass();
        $username_token->UsernameToken = new SoapVar($auth, SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'UsernameToken', $this->wss_ns);

        $security_sv = new SoapVar(
                new SoapVar($username_token, SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'UsernameToken', $this->wss_ns), SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'Security', $this->wss_ns);
        parent::__construct($this->wss_ns, 'Security', $security_sv, true);
    }

}

$username = 'username';
$password = 'password';
$wsdl = 'url';

$wsse_header = new WsseAuthHeader($username, $password);

$client = new SoapClient($wsdl, array(
    "trace" => 1,
    "exceptions" => 0,
    'SOAPAction' => 'http://tempuri.org/GetXMLDatabyID',
    'header' => 'Content-Type: text/xml; charset=utf-8'
        )
);

$client->__setSoapHeaders(array($wsse_header));

$request = array(
    'GetXMLDatabyIDResult' => array(
        'id' => '313371',
        'AgentName' => 'TEST',
    )
);

$results = $client->getXMLDatabyID($request);

print_r($results);

Я хочу получить такие данные в PHP (Результат)

<Name>JOHN PAUL CORNELIUS</Name>
<DOB>1980-11-12T00:00:00+08:00</DOB>

Проблема в том, что у меня нет опыта работы с SOAP в PHP, поэтому я застрял. Кто-нибудь может мне помочь?

Спасибо:)

0 ответов

Другие вопросы по тегам