簡體   English   中英

PHP SOAP 請求未填充 XML 參數

[英]PHP SOAP request not populating XML parameter

我正在嘗試進行簡單的 SOAP 調用:

$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); 

當我檢查 $xmlstring2 變量時,我發現它確實由我的 XML 字符串填充:

<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>

但是,當我使用:

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

我得到以下信息:

<?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>

XML 未填充到 SOAP 調用中。 我檢查了文檔,但我無法確定我出錯的地方。 這些是 WSDL 函數:

<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>

如果沒有完整的 WSDL,我認為您應該嘗試:

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

然后看看

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

並查看是否填充了這些參數,但請注意,它實際上可能需要第三個參數的正確結構才能對其進行正確編碼。 注意 wsdl 中的 minOccurs="1" 並將 p 准備為常規的 php 數組。 它應該工作。 如果沒有,請閱讀有關 php soal __soapCall + SoapParam 數組的信息,但這不是必需的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM