dsl36367 2018-10-19 22:33
浏览 55
已采纳

PHP Soap不会创建正确的xml文档

I am trying to use this WSDL-service: https://wsaimport.uni-login.dk/wsaimport-v5/ws?WSDL

It needs an XML-document with information about users to import. When importing a person, two attributes are mandatory (according to https://wsaimport.uni-login.dk/wsaimport-v5/ws?xsd=1): (e.g. <xs:attribute name="protected" type="xs:boolean" use="required">).

I produce an object with the required information (and more, of course) (the user and personal id are fake):

object(XMLinst)#5 (1) { ["UNILoginImport"]=> object(UNILoginImport)#6 (5) { ["sourceDateTime"]=> string(19) "2018-10-20T00:15:54" ["source"]=> string(10) "SurveyInfo" ["schoolYear"]=> string(9) "2018-2019" ["sourceVersion"]=> string(3) "0.1" ["Institution"]=> object(Institution)#7 (4) { ["InstitutionNumber"]=> string(5) "10150" ["InstitutionName"]=> NULL ["Group"]=> object(Group)#8 (7) { ["GroupId"]=> string(2) "7b" ["GroupName"]=> string(3) "7.B" ["GroupType"]=> string(11) "Hovedgruppe" ["GroupLevel"]=> string(2) "DT" ["Line"]=> string(1) "B" ["FromDate"]=> string(10) "2018-08-01" ["ToDate"]=> string(10) "2019-06-30" } ["InstitutionPerson"]=> array(1) { [0]=> object(InstitutionPerson)#9 (5) { ["LocalPersonId"]=> string(11) "310900-8345" ["Person"]=> object(Person)#10 (16) { ["protected"]=> bool(false) ["verificationLevel"]=> string(1) "0" ["FirstName"]=> string(9) "Tester A." ["FamilyName"]=> string(9) "Testersen" ["CivilRegistrationNumber"]=> string(11) "310900-8345" ["EmailAddress"]=> NULL ["BirthDate"]=> string(10) "2000-09-31" ["Gender"]=> string(1) "M" ["PhotoId"]=> NULL ["AliasFirstName"]=> NULL ["AliasFamilyName"]=> NULL ["Address"]=> NULL ["HomePhoneNumber"]=> NULL ["WorkPhoneNumber"]=> NULL ["MobilePhoneNumber"]=> NULL ["GroupId"]=> string(2) "7b" } ["Student"]=> object(Student)#11 (6) { ["Role"]=> string(4) "Elev" ["StudentNumber"]=> NULL ["Level"]=> string(2) "DT" ["Location"]=> string(8) "B-rummet" ["MainGroupId"]=> string(2) "7b" ["GroupId"]=> NULL } ["Employee"]=> NULL ["Extern"]=> NULL } } } } }

I am calling the client, and then the import function:

$unilogin = new SoapClient($WSDL,array("soap_version" => SOAP_1_2,'cafile' => "/etc/ssl/certs/surveyinfo.pem", 'cache_wsdl'=>"WSDL_CACHE_NONE", 'cache'=>"WSDL_CACHE_NONE", 'trace'=>true));

$unilogin->importerDeltaXml(array("wsBrugerid"=>$user,"wsPassword"=>$pass,"xml"=>$import));

This returns an error:

org.xml.sax.SAXParseException; cvc-complex-type.4: Attribute 'protected' must appear on element 'ns3:Person'.

The return from getLastResponse looks like this:

<?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="https://uni-login.dk" xmlns:ns2="https://uni-login.dk/data" xmlns:ns3="https://wsaimport.uni-login.dk/import" xmlns:ns4="https://wsaimport.uni-login.dk/ws"><env:Body><ns4:importerDeltaXml><ns1:wsBrugerid/><ns1:wsPassword/><ns4:xml><ns3:UNILoginImport sourceVersion="0.1" sourceDateTime="2018-10-20T00:12:28" source="SurveyInfo" schoolYear="2018-2019"><ns3:Institution><ns2:InstitutionNumber>10150</ns2:InstitutionNumber><ns2:Group><ns2:GroupId>7b</ns2:GroupId><ns2:GroupName>7.B</ns2:GroupName><ns2:GroupType>Hovedgruppe</ns2:GroupType><ns2:GroupLevel>DT</ns2:GroupLevel><ns2:Line>B</ns2:Line><ns2:FromDate>2018-08-01</ns2:FromDate><ns2:ToDate>2019-06-30</ns2:ToDate></ns2:Group><ns3:InstitutionPerson><ns2:LocalPersonId>310400-8444</ns2:LocalPersonId><ns3:Person><ns2:FirstName>Tester A.</ns2:FirstName><ns2:FamilyName>Testersen</ns2:FamilyName><ns2:CivilRegistrationNumber>310400-8444</ns2:CivilRegistrationNumber><ns2:BirthDate>2000-04-31</ns2:BirthDate><ns2:Gender>K</ns2:Gender></ns3:Person><ns3:Student><ns2:Role>Elev</ns2:Role><ns2:Level>DT</ns2:Level><ns2:Location>B-rummet</ns2:Location><ns2:MainGroupId>7b</ns2:MainGroupId></ns3:Student></ns3:InstitutionPerson></ns3:Institution></ns3:UNILoginImport></ns4:xml></ns4:importerDeltaXml></env:Body></env:Envelope>

As you can see, the protected and verificationLevel are not part of the XML, even though they were present in the object presented to SOAP. As you can also see, the SOAP-client function in PHP is actually capable of producing attributes as requested by the WSDL-document, because it is done in the <ns3:UNILoginImport> tag.

Have I come accross a bug in PHP's SoapClient? Or is something wrong in the WSDL-documents? (it is produced by a Danish Government agency, and a number of companies are using it already).

Any advice on how to get around this problem? I have tried to use the XML-document I get from __getLastRequest, inserting the requested attributes, but when sending this XML-document, after putting it through new SoapVar, I get "Failed to copy a message"... Thanks!

  • 写回答

1条回答 默认 最新

  • dongmeixi5311 2018-11-18 13:34
    关注

    I found a workaround by extending the SOAP-client the following way:

    class HackSoapClient extends SoapClient {
    
            function __doRequest($request, $location, $action, $version, $one_way = NULL) {
    
                $request=str_replace('<ns3:Person>','<ns3:Person protected="false" verificationLevel="0">',$request);
                // parent call
                return parent::__doRequest($request, $location, $action, $version,$one_way);
            }
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 ubuntu系统下挂载磁盘上执行./提示权限不够
  • ¥15 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 关于#r语言#的问题:差异分析前数据准备,报错Error in data[, sampleName1] : subscript out of bounds请问怎么解决呀以下是全部代码:
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误