Nimrod Yanai
Nimrod Yanai

Reputation: 819

PHP SOAP request not populating XML parameter

I am trying to make a simple SOAP call:

$aHTTP['http']['header'] =  "Content-Type: text/xml; charset=utf-8";
$aHTTP['http']['header'] =  "SOAPAction: http://url.com/LoginAndGetStudentsData";
$context = stream_context_create($aHTTP);
$options = array(
    'soap_version'=> SOAP_1_1,
    'trace'=> true,
    'exceptions'=> true,                // disable exceptions
    'features'=> SOAP_SINGLE_ELEMENT_ARRAYS,
    'encoding'=> 'UTF-8',
    'cache_wsdl'=>WSDL_CACHE_NONE,
    'stream_context=>'=>$context,
);
$client  = new SoapClient($baseURL."?wsdl", $options);
$response = $client->LoginAndGetStudentsData($xmlstring2); 

When I check the $xmlstring2 variable, I see it is indeed populated by my XML string:

<username>****</username>
<password>****</password>
<p><OrbitId>1</OrbitId><HasLessons xsi:nil="true"/><HasLearningPrograms xsi:nil="true"/><ContextYear>2020</ContextYear><IdNumber xsi:nil="true"/><FillExtraFields>true</FillExtraFields><FromUpdateDate xsi:nil="true"/><ToUpdateDate xsi:nil="true"/><IncludeDivisionInfo>true</IncludeDivisionInfo><IncludeProgramInfo>true</IncludeProgramInfo><IncludeAccumulatedAcademicPoints>false</IncludeAccumulatedAcademicPoints><IncludeMoneyBalanceInfo>false</IncludeMoneyBalanceInfo><IncludePassportImage>false</IncludePassportImage><IncludeSpecializationData>true</IncludeSpecializationData><IncludeWsProgramInfoDetails>false</IncludeWsProgramInfoDetails><IncludeRegistraionRoadMaps>false</IncludeRegistraionRoadMaps><FromStudentCreationDate xsi:nil="true"/><ToStudentCreationDate xsi:nil="true"/><FromStudentLearningProgramUpdateDate xsi:nil="true"/><ToStudentLearningProgramUpdateDate xsi:nil="true"/><FromRegistraionRoadMapUpdateDate xsi:nil="true"/><ToRegistraionRoadMapUpdateDate xsi:nil="true"/></p>

However, when I use:

die("Request: ".$client->__getLastRequest()."\nEnd Request");

I get the following:

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

The XML is not populated in the SOAP call. I checked the documentation, but I can't fine what I'm getting wrong. These are the WSDL functions:

<wsdl:definitions xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://url.net/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://url.net/">
<script/>
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="http://url.net/">
<s:element name="LoginAndGetStudentsData">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="username" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="password" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="p" type="tns:StudentRequestParameters"/>
</s:sequence>
</s:complexType>
</s:element>
<s:complexType name="StudentRequestParameters">
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="OrbitId" nillable="true" type="s:int"/>
<s:element minOccurs="0" maxOccurs="1" name="OrbitIds" type="tns:ArrayOfInt"/>
<s:element minOccurs="1" maxOccurs="1" name="HasLessons" nillable="true" type="s:boolean"/>
<s:element minOccurs="1" maxOccurs="1" name="HasLearningPrograms" nillable="true" type="s:boolean"/>
<s:element minOccurs="1" maxOccurs="1" name="ContextYear" nillable="true" type="s:int"/>
<s:element minOccurs="1" maxOccurs="1" name="IdNumber" nillable="true" type="s:int"/>
<s:element minOccurs="1" maxOccurs="1" name="FillExtraFields" nillable="true" type="s:boolean"/>
<s:element minOccurs="1" maxOccurs="1" name="FromUpdateDate" nillable="true" type="s:dateTime"/>
<s:element minOccurs="1" maxOccurs="1" name="ToUpdateDate" nillable="true" type="s:dateTime"/>
<s:element minOccurs="1" maxOccurs="1" name="IncludeDivisionInfo" nillable="true" type="s:boolean"/>
<s:element minOccurs="1" maxOccurs="1" name="IncludeProgramInfo" nillable="true" type="s:boolean"/>
<s:element minOccurs="1" maxOccurs="1" name="IncludeAccumulatedAcademicPoints" type="s:boolean"/>
<s:element minOccurs="1" maxOccurs="1" name="IncludeMoneyBalanceInfo" nillable="true" type="s:boolean"/>
<s:element minOccurs="1" maxOccurs="1" name="IncludePassportImage" nillable="true" type="s:boolean"/>
<s:element minOccurs="1" maxOccurs="1" name="IncludeSpecializationData" nillable="true" type="s:boolean"/>
<s:element minOccurs="0" maxOccurs="1" name="OtherId" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="FullNameContains" type="s:string"/>
<s:element minOccurs="1" maxOccurs="1" name="IncludeWsProgramInfoDetails" type="s:boolean"/>
<s:element minOccurs="1" maxOccurs="1" name="IncludeRegistraionRoadMaps" nillable="true" type="s:boolean"/>
<s:element minOccurs="1" maxOccurs="1" name="FromStudentCreationDate" nillable="true" type="s:dateTime"/>
<s:element minOccurs="1" maxOccurs="1" name="ToStudentCreationDate" nillable="true" type="s:dateTime"/>
<s:element minOccurs="1" maxOccurs="1" name="FromStudentLearningProgramUpdateDate" nillable="true" type="s:dateTime"/>
<s:element minOccurs="1" maxOccurs="1" name="ToStudentLearningProgramUpdateDate" nillable="true" type="s:dateTime"/>
<s:element minOccurs="1" maxOccurs="1" name="FromRegistraionRoadMapUpdateDate" nillable="true" type="s:dateTime"/>
<s:element minOccurs="1" maxOccurs="1" name="ToRegistraionRoadMapUpdateDate" nillable="true" type="s:dateTime"/>
<s:element minOccurs="0" maxOccurs="1" name="Phone" type="s:string"/>
</s:sequence>
</s:complexType>

Upvotes: 0

Views: 89

Answers (1)

Greg
Greg

Reputation: 708

Without complete WSDL I think you should try:

$response = $client->LoginAndGetStudentsData(['username'=>'foo','password'=>'bar', 'p'=>[]]);

Then look at

die("Request: ".$client->__getLastRequest()."\nEnd Request");

and see if those parameters are populated but be aware that it might actually require proper structure of third parameter to properly encode it. Note minOccurs="1" in that wsdl and prepare p as regular php array. It should work. If not then read about php soal __soapCall + array of SoapParam but that should not be necessary.

Upvotes: 1

Related Questions