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 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000