PHP SOAP请求发送多个stdclass对象

时间:2016-12-04 15:53:18

标签: php object soap merge

我正在尝试发送一个包含多个stdclass对象的PHP SOAP请求。我无法弄清楚如何发送所以xml格式正确。 xml结构应如下所示(来自SOAPui)。

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
 xmlns:ass="http://assignment.soap.assignshare" 
 xmlns:xsd="http://request.assignment.soap.assignshare/xsd" 
 xmlns:xsd1="http://datamodel.assignment.soap.assignshare/xsd">
   <soapenv:Header/>
   <soapenv:Body>
      <ass:SetStaffOnDutyStatus>
         <ass:SasPubSetStaffOnDutyStatus>
            <xsd:Source>VendorC</xsd:Source>
            <xsd:Dest>?</xsd:Dest>
            <xsd:PubEventMsgTag>1</xsd:PubEventMsgTag>
            <xsd:EventSetStaffOnDutyStatus>
               <xsd:Timestamp>Thurs,03 Nov 2016,20:20:00 GMT</xsd:Timestamp>
               <xsd:EventAction>Set</xsd:EventAction>
               <xsd:Staff>
                  <xsd1:StaffID>10</xsd1:StaffID>
                  <xsd1:Last>Doe</xsd1:Last>
                  <xsd1:First>John</xsd1:First>
                  <xsd1:Middle>?</xsd1:Middle>
                  <xsd1:Role>?</xsd1:Role>
               </xsd:Staff>
               <xsd:Team>
                  <xsd1:TeamID>319</xsd1:TeamID>
                  <xsd1:TeamName>5 East</xsd1:TeamName>
               </xsd:Team>
            </xsd:EventSetStaffOnDutyStatus>
         </ass:SasPubSetStaffOnDutyStatus>
      </ass:SetStaffOnDutyStatus>
   </soapenv:Body>
</soapenv:Envelope>

我的PHP文件是

<?php

    $a = new StdClass();
    $a->SasPubSetStaffOnDutyStatus = new StdClass();
    $a->SasPubSetStaffOnDutyStatus->Source = 'Demo';
    $a->SasPubSetStaffOnDutyStatus->Dest = 'http://192.168.50.3:26001/SAIWebService';
    $a->SasPubSetStaffOnDutyStatus->PubEventMsgTag = 1;
    $a->SasPubSetStaffOnDutyStatus->EventSetStaffOnDutyStatus = new StdClass($b);

    $b = new StdClass();
    $b->EventSetStaffOnDutyStatus = new StdClass();
    $b->EventSetStaffOnDutyStatus->Timestamp = 'Thurs,03 Nov 2016,20:20:00 GMT';
    $b->EventSetStaffOnDutyStatus->EventAction = 'Set';

    $c = new StdClass();
    $c->Staff = new StdClass();
    $c->Staff->StaffID = 10;
    $c->Staff->Last = 'Harry';
    $c->Staff->First = 'Potter';
    $c->Staff->Middle = '?';
    $c->Staff->Role = '?';

    $d = new StdClass();
    $d->Team = new StdClass();
    $d->Team->TeamID = 319;
    $d->Team->TeamName = '5 East';

    $d = (object)array_merge ((array)$b, (array)$c, (array)$d);
    $e = (object)array_merge((array)$a, (array)$d);

    $wsdl = "http://192.xxx.xx.x:26001/SAIWebservice?singlewsdl";

    $client = new SoapClient($wsdl, array(
                            "trace"=>1,
                            "exceptions"=>0));

    $values = $client->SetStaffOnDutyStatus($e);
    echo "REQUEST HEADERS:\n" . $client->__getLastRequestHeaders() . "\n";

    $xml = $values->SasPubRespSetStaffOnDutyStatus;
    print "<pre>\n";
    print_r($xml);
    print "</pre>";

PHP文件的输出不包含对象$ b,$ c&amp;的值。 $ d。对我合并对象的错误提出任何指导。输出低于。

    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="http://request.assignment.soap.assignshare/xsd"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:ns2="http://assignment.soap.assignshare">
 <SOAP-ENV:Body>
    <ns2:SetStaffOnDutyStatus>
        <ns2:SasPubSetStaffOnDutyStatus>
            <ns1:Source>Demo</ns1:Source>
            <ns1:Dest>http://192.168.50.3:26001/SAIWebService</ns1:Dest>
            <ns1:PubEventMsgTag>1</ns1:PubEventMsgTag>
            <ns1:EventSetStaffOnDutyStatus>
            <ns1:Timestamp xsi:nil="true"/>
            <ns1:EventAction xsi:nil="true"/>
            <ns1:Staff xsi:nil="true"/>
            <ns1:Team xsi:nil="true"/>
            </ns1:EventSetStaffOnDutyStatus>
        </ns2:SasPubSetStaffOnDutyStatus>
    </ns2:SetStaffOnDutyStatus>
</SOAP-ENV:Body></SOAP-ENV:Envelope>

0 个答案:

没有答案