После обновления PHP 5.6.16 до 7.2.9 SoapClient :: __ doRequest () не работает всегда возвращает пустой ответ - PullRequest
0 голосов
/ 24 февраля 2020

После обновления PHP 7.2.9 SoapClient перестал работать правильно и всегда возвращается пустым.

Клиентский файл

<?php

$xml = '<?xml version="1.0" encoding="ISO-8859-1"?>';
$xml .= '<SOAP-ENV:Envelope xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">';
$xml .= '<SOAP-ENV:Body>';
$xml .= '<Authenticate>';
$xml .= '<Username>guest</Username>';
$xml .= '<Password>welcome</Password>';
$xml .= '<Locale>en_US</Locale>';
$xml .= '<ValidityInMin>60</ValidityInMin>';
$xml .= '<isGlobal>true</isGlobal>';
$xml .= '</Authenticate>';
$xml .= '</SOAP-ENV:Body>';
$xml .= '</SOAP-ENV:Envelope>';

$url='https://test.mylocal.com/soapresponse.php?actionkey=authenticate';


$opts = array(
    'ssl' => array('verify_peer'=>FALSE,
        'verify_peer_name'=>FALSE,
        )
);

$soapOptions = array(
    'soap_version'   => SOAP_1_2,
    'location'=>$url,
    'uri'=>$url,
    'exceptions'=> 0,
    'trace'=>true,
    'cache_wsdl' => WSDL_CACHE_NONE,
    'stream_context' => stream_context_create($opts),

);
$client = new SoapClient("test.wsdl",$soapOptions);

$xmlstr = $client->__doRequest($xml,$url,'',1);

var_dump($client->__getLastResponseHeaders());
var_dump($client->__getLastResponse());
?>

SOAP серверный файл

<?php

class AuthenticateService {

    public function authenticate($requestData){
        try{
           // do some business logics and the result will be framed like below

            $cert=Array();
            $cert[0]=new StdClass();
            $cert[0]->SPCertificate="test111";
            $cert[0]->SPLearnerLicense="test234";
            $cert[0]->SPAdminLicense="lic4334";
            $cert[0]->SPLearnerInfo="ssdsfr834544";
            $cert[0]->Name="test";
            $cert[0]->UserName="test";
            $cert[0]->UserId=44; 

            $outData=$cert;

            return $outData;
        }catch(Exception $e){

            throw new SoapFault("SPLMS",$e->getMessage());

        }
    }


}
$server = new SoapServer("test.wsdl",array('soap_version' => SOAP_1_2));
$server->setClass("AuthenticateService");
$server->handle();

?>

WSDL-файл

<?xml version='1.0' encoding='UTF-8'?>
<wsdl:definitions name='authenticate' targetNamespace="https://test.mylocal.com/wsdl/wsdlschema.xsd" 
    xmlns:expertus='https://test.mylocal.com/sites/all/modules/core/exp_sp_core/wsdl/wsdlschema.xsd'
    xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
    xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/'
    xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/' xmlns='http://schemas.xmlsoap.org/wsdl/'>

    <wsdl:types>
      <xsd:schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="https://test.mylocal.com/wsdl/wsdlschema.xsd">
         <xsd:include schemaLocation="/wsdl/wsdlschema.xsd"/>    
         <xsd:complexType name="AuthResponse">
            <xsd:sequence>
                <xsd:element name='SPCertificate' type='xsd:string'/>
            </xsd:sequence>
         </xsd:complexType>
         <xsd:complexType name="validateUserRequest">
            <xsd:sequence>
                <xsd:element name="name" type="xsd:string" /> 
                <xsd:element name="pass" type="xsd:string" />
            </xsd:sequence>
        </xsd:complexType>
        <xsd:complexType name="validateEmail">
            <xsd:sequence>
                <xsd:element name="email" type="xsd:string" />
            </xsd:sequence>
        </xsd:complexType>
        <xsd:complexType name="validateCaptcha">
            <xsd:sequence>
                <xsd:element name="captcha" type="xsd:string" /> 
                <xsd:element name="captcha_entered" type="xsd:string" />
            </xsd:sequence>
        </xsd:complexType>

        <xsd:complexType name="Authenticate">
        <xsd:sequence>
            <xsd:element name='Username' type='xsd:string' />
            <xsd:element name='Password' type='xsd:string' />
            <xsd:element name='Locale' type='xsd:string' />
            <xsd:element name='ValidityInMin' type='xsd:string' />
            <xsd:element name='isGlobal' type='xsd:string' minOccurs='0' />
        </xsd:sequence>
     </xsd:complexType>

     <xsd:complexType name="Certificate">
      <xsd:simpleContent>
        <xsd:extension base="string">
            <xsd:attribute name="Id" type="string" />
            <xsd:attribute name="UserName" type="string" />
            <xsd:attribute name="Name" type="string" /> 
        </xsd:extension>
      </xsd:simpleContent>
    </xsd:complexType>


       </xsd:schema>
     </wsdl:types>

    <wsdl:message name='authenticateServiceRequest'>
         <wsdl:part name="Authenticate" type="expertus:Authenticate"/>
    </wsdl:message>

    <wsdl:message name='authenticateServiceResponse'>
        <wsdl:part name='Certificate' type='expertus:AuthResponse' />
        <wsdl:part name='Token' type='xsd:string' />
    </wsdl:message>

    <wsdl:message name="ValidateUserServiceRequest">
        <wsdl:part name="ValidateUserService" type="expertus:validateUserRequest"/>
    </wsdl:message>
    <wsdl:message name="ValidateUserServiceResponse">
        <wsdl:part name="ValidateUserService" element="xsd:string" />
    </wsdl:message>
    <wsdl:message name="GenerateCaptchaServiceRequest">
        <wsdl:part name="GenerateCaptcha" element="xsd:string"/>
    </wsdl:message>
    <wsdl:message name="GenerateCaptchaServiceResponse">
        <wsdl:part name="GenerateCaptcha" element="xsd:string" />
    </wsdl:message>
    <wsdl:message name="ValidateCaptchaServiceRequest">
        <wsdl:part name="ValidateCaptcha" type="expertus:validateCaptcha"/>
    </wsdl:message>
    <wsdl:message name="ValidateCaptchaServiceResponse">
        <wsdl:part name="ValidateCaptcha" element="xsd:string" />
    </wsdl:message>
    <wsdl:message name="ValidateUsernameServiceRequest">
        <wsdl:part name="ValidateUsername" type="expertus:validateUserRequest"/>
    </wsdl:message>
    <wsdl:message name="ValidateUsernameServiceResponse">
        <wsdl:part name="ValidateUsername" element="xsd:string" />
    </wsdl:message>
    <wsdl:message name="ValidateEmailRequest">
        <wsdl:part name="ValidateEmail" type="expertus:validateEmail"/>
    </wsdl:message>
    <wsdl:message name="ValidateEmailResponse">
        <wsdl:part name="ValidateEmail" element="xsd:string" />
    </wsdl:message>

    <wsdl:portType name='AuthenticateServicePortType'>
        <wsdl:operation name='authenticate'>
            <wsdl:input name="authenticateServiceReq" message='expertus:authenticateServiceRequest' />
            <wsdl:output name="authenticateServiceRes" message='expertus:authenticateServiceResponse' />
        </wsdl:operation>
    </wsdl:portType>

    <wsdl:portType name="ValidateUserServicePortType">
        <wsdl:operation name="validateUser">
            <wsdl:input name="ValidateUserServiceReq" message="expertus:ValidateUserServiceRequest" />
            <wsdl:output name="ValidateUserServiceRes" message="expertus:ValidateUserServiceResponse" />
        </wsdl:operation>
    </wsdl:portType>

    <wsdl:portType name="GenerateCaptchaServicePortType">
        <wsdl:operation name="generateCaptcha">
            <wsdl:input name="GenerateCaptchaServiceReq" message="expertus:GenerateCaptchaServiceRequest" />
            <wsdl:output name="GenerateCaptchaServiceRes" message="expertus:GenerateCaptchaServiceResponse" />
        </wsdl:operation>
    </wsdl:portType>

    <wsdl:portType name="ValidateCaptchaServicePortType">
        <wsdl:operation name="validateCaptcha">
            <wsdl:input name="ValidateCaptchaServiceReq" message="expertus:ValidateCaptchaServiceRequest" />
            <wsdl:output name="ValidateCaptchaServiceRes" message="expertus:ValidateCaptchaServiceResponse" />
        </wsdl:operation>
    </wsdl:portType>

    <wsdl:portType name="ValidateUsernameServicePortType">
        <wsdl:operation name="validateUsername">
            <wsdl:input name="ValidateUsernameServiceReq" message="expertus:ValidateUsernameServiceRequest" />
            <wsdl:output name="ValidateUsernameServiceRes" message="expertus:ValidateUsernameServiceResponse" />
        </wsdl:operation>
    </wsdl:portType>
    <wsdl:portType name="ValidateEmailPortType">
        <wsdl:operation name="validateEmail">
            <wsdl:input name="ValidateEmailReq" message="expertus:ValidateEmailRequest" />
            <wsdl:output name="ValidateEmailRes" message="expertus:ValidateEmailResponse" />
        </wsdl:operation>
    </wsdl:portType>

    <wsdl:binding name='AuthenticateServiceBinding' type='expertus:AuthenticateServicePortType'>
        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
        <wsdl:operation name='authenticate'>
            <soap:operation soapAction=" " style="document" />
            <wsdl:input>
                <soap:body use='literal' />
            </wsdl:input>
            <wsdl:output>
                <soap:body use='literal' />
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>

    <wsdl:binding name='ValidateUserServiceBinding' type='expertus:ValidateUserServicePortType'>
        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
        <wsdl:operation name='validateUser'>
            <soap:operation soapAction=" " style="document" />
            <wsdl:input>
                <soap:body use='literal' />
            </wsdl:input>
            <wsdl:output>
                <soap:body use='literal' />
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>

    <wsdl:binding name='GenerateCaptchaServiceBinding' type='expertus:GenerateCaptchaServicePortType'>
        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
        <wsdl:operation name='generateCaptcha'>
            <soap:operation soapAction=" " style="document" />
            <wsdl:input>
                <soap:body use='literal' />
            </wsdl:input>
            <wsdl:output>
                <soap:body use='literal'  />
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>

    <wsdl:binding name='ValidateCaptchaServiceBinding' type='expertus:ValidateCaptchaServicePortType'>
        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
        <wsdl:operation name='validateCaptcha'>
            <soap:operation soapAction=" " style="document" />
            <wsdl:input>
                <soap:body use='literal'  />
            </wsdl:input>
            <wsdl:output>
                <soap:body use='literal'  />
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>

    <wsdl:binding name='ValidateUsernameServiceBinding' type='expertus:ValidateUsernameServicePortType'>
        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
        <wsdl:operation name='validateUsername'>
            <soap:operation soapAction=" " style="document" />
            <wsdl:input>
                <soap:body use='literal'  />
            </wsdl:input>
            <wsdl:output>
                <soap:body use='literal'  />
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:binding name='ValidateEmailBinding' type='expertus:ValidateEmailPortType'>
        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
        <wsdl:operation name='validateEmail'>
            <soap:operation soapAction=" " style="document" />
            <wsdl:input>
                <soap:body use='literal'  />
            </wsdl:input>
            <wsdl:output>
                <soap:body use='literal'  />
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name='AuthenticateService'>
        <wsdl:port name='AuthenticateServicePort' binding='expertus:AuthenticateServiceBinding'>
            <soap:address location='https://test.mylocal.com/sites/all/services/Service.php' />
        </wsdl:port>
        <wsdl:port name="ValidateUserServicePort" binding="expertus:ValidateUserServiceBinding">
            <soap:address location="https://test.mylocal.com/sites/all/services/Service.php" />
        </wsdl:port>
        <wsdl:port name="GenerateCaptchaServicePort" binding="expertus:GenerateCaptchaServiceBinding">
            <soap:address location="https://test.mylocal.com/sites/all/services/Service.php" />
        </wsdl:port>
        <wsdl:port name="ValidateCaptchaServicePort" binding="expertus:ValidateCaptchaServiceBinding">
            <soap:address location="https://test.mylocal.com/sites/all/services/Service.php" />
        </wsdl:port>
        <wsdl:port name="ValidateUsernameServicePort" binding="expertus:ValidateUsernameServiceBinding">
            <soap:address location="https://test.mylocal.com/sites/all/services/Service.php" />
        </wsdl:port>
        <wsdl:port name="ValidateEmailPort" binding="expertus:ValidateEmailBinding">
            <soap:address location="https://test.mylocal.com/sites/all/services/Service.php" />
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>

Тем не менее тот же код отлично работает в 5.6 .16 только в 7.2.9 не работает заголовок ответа отправит 200 статус, но тело ответа пусто.

На стороне сервера, если я использую SoapVar (), я получаю ответ в xml с пустым телом вроде

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body/></SOAP-ENV:Envelope>

Пожалуйста, помогите мне решить эту проблему.

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