使用 PHP SoapClient 创建原始 XML 请求


Create raw XML request using PHP SoapClient

我正在尝试使用SoapVar创建原始XML请求。这是我的代码

#- Loading the WSDL document
  $wsdl = "https://ota2-p1.ihotelier.com/OTA_Seamless/services/DailyRateService?wsdl";
  $client = new SoapClient($wsdl,array('trace' => true, 'exceptions' => true));
#- Creating the XML document
   $xml = <<<EOT
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ota="http://services.ota.travelclick.com">
<soap:Header>
   <wsa:MessageID>86830</wsa:MessageID>
   <wsa:ReplyTo>
      <wsa:Address>NOT NEEDED FOR SYNC REQUEST</wsa:Address>
   </wsa:ReplyTo>
   <wsa:To>https://ota2-p1.ihotelier.com/OTA_Seamless/services/DailyRateService</wsa:To>
   <wsa:Action>DailyRate</wsa:Action>
   <wsa:From>
      <SalesChannelInfo ID="XXXXXXXXX"/><!-- Fields to be provided by TC -->
   </wsa:From>
   <wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/07/secext">
      <wsu:Timestamp xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
         <wsu:Created>2016-02-05T15:55:56+00:00</wsu:Created>
         <wsu:Expires>2016-02-06T15:56:06+00:00</wsu:Expires>
      </wsu:Timestamp>
      <wsse:UsernameToken>
         <wsse:Username>XXXXX</wsse:Username><!-- Fields to be provided by TC -->
         <wsse:Password>XXXXXX</wsse:Password><!-- Fields to be provided by TC -->
      </wsse:UsernameToken>
   </wsse:Security>
</soap:Header>
<soap:Body>
<OTA_HotelAvailRQ Version="2.0" AvailRatesOnly="False" TimeStamp="2016-02-05T15:55:56+00:00">
   <POS>
      <Source>
         <RequestorID Type="1" ID="" MessagePassword=""/><!-- Fields to be provided by TC -->
         <BookingChannel Type="18">
            <CompanyName CompanyShortName="" Code=""/><!-- Fields to be provided by TC -->
         </BookingChannel>
      </Source>
   </POS>
   <AvailRequestSegments>
      <AvailRequestSegment ResponseType="DailyRateList"><!-- request type -->
         <HotelSearchCriteria AvailableOnlyIndicator="false">
            <Criterion>
               <HotelRef HotelCode="97593"/><!-- iHotelierID -->
               <StayDateRange Start="2016-02-08" End="2016-02-15"/>
               <RoomStayCandidates>
                  <RoomStayCandidate Quantity="1">
                     <GuestCounts>
                        <GuestCount AgeQualifyingCode="10" Count="1"/><!-- Adult -->
                        <GuestCount AgeQualifyingCode="8" Count="0"/><!-- Child -->
                        <GuestCount AgeQualifyingCode="7" Count="0"/><!-- Infant -->
                     </GuestCounts>
                  </RoomStayCandidate>
               </RoomStayCandidates>
            </Criterion>
         </HotelSearchCriteria>
      </AvailRequestSegment>
   </AvailRequestSegments>
</OTA_HotelAvailRQ>
</soap:Body></soap:Envelope>
EOT;
   $body = new SoapVar($xml,XSD_ANYXML);
#- Calling the service method
   $result = $client->serviceRequest($body);

#- Showing the request and response
   echo '<pre>', htmlentities($client->__getLastRequest()), '</pre>';
   echo "<br> --------response---------<br>";
   echo '<pre>', htmlentities($client->__getLastResponse()), '</pre>';

我收到此错误

Fatal error: Uncaught SoapFault exception: [soapenv:Client.2000] Mandatory values missing in the Message Header...

已按照本教程操作。我做错了什么?

如果此方法错误,如何为上述 XML 请求创建 soap 标头和正文?

这个问题很难回答,因为它缺乏测试示例所需的文档和参数。它似乎也是一种需要帐户的付费商业服务。

因此,也许我们能做的最好的事情就是演示如何从同一站点使用更简单的服务。这个不需要任何参数,并返回如下所示的版本。

此处提供了其他服务的列表。

<?php 
    try {
        $client = new SoapClient('https://ota2-p1.ihotelier.com/OTA_Seamless/services/Version?wsdl');
        $result = $client->getVersion( );
        print_r($result);
   }
   catch(Exception $e) {
       echo "'nException:" .$e->getMessage();
   }
?> 

网络服务返回:

Apache Axis version: 1.4 Built on Apr 22, 2006 (06:55:48 PDT)