1

您好,我对 web 服务非常陌生,在 php 中使用以下代码我正在尝试发出如下 XML 所示的肥皂请求,但它显示 错误

HTTP 错误:不支持的 HTTP 响应状态 405 Method Not Allowed(soapclient->response 有响应的内容)

Q. 1)如何传递标头 2)如何传递 FetchCalendarRequest

我在这里使用过 nusoap,但如果你有soap php 类解决方案,也会被邀请。

    <?php

    error_reporting(E_ALL);


   require("../lib/nusoap.php");

error_reporting(E_ALL ^ E_NOTICE);
$ERROR_MSG = '';

$s_WSPROTOCOL = 'http';
$s_WSHOSTNAME = '###.###.###.##';
$s_WSPORT = ':8080';
$s_WSPATHNAME = 'ows_ws_51/Availability.asmx?WSDL';         
$s_WSTIPOOP = 'FetchCalendar';

$parameters['StayDateRange'] = array('StartDate' => '2013-10-01','EndDate' => '2013-10-10');


echo $s_WSTIPOOP."<br />";
echo $s_WSPROTOCOL."://".$s_WSHOSTNAME.$s_WSPORT."/".$s_WSPATHNAME."<br /><br /><br />";     
$client = new nusoap_client($s_WSPROTOCOL."://".$s_WSHOSTNAME.$s_WSPORT."/".$s_WSPATHNAME, true);

$result = $client->call($s_WSTIPOOP, $parameters);

if ($client->fault) {

echo '<h2>Fault (Expect - The request contains an invalid SOAP body)</h2><pre>'; 
print_r($result); echo '</pre>';

} else {

$err = $client->getError();
if ($err) {

echo '<h2>Error</h2><pre>' . $err . '</pre>';

} else {
echo '<h2>Result</h2><pre>'; print_r($result); echo '</pre>';
}
}

echo '<h2>Request</h2><pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2><pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->getDebug(), ENT_QUOTES) . '</pre>';

    ?>

XML

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Header>
    <OGHeader transactionID="005435" timeStamp="2008-12-09T13:26:56.4056250-05:00" xmlns="http://webservices.test.com/og/4.3/Core/">
      <Origin entityID="OWS" systemType="WEB" />
      <Destination entityID="WEST" systemType="ORS" />
    </OGHeader>
  </soap:Header>
  <soap:Body>
    <FetchCalendarRequest xmlns:a="http://webservices.test.com/og/4.3/Availability/" xmlns:hc="http://webservices.test.com/og/4.3/HotelCommon/" xmlns="http://webservices.test.com/ows/5.1/Availability.wsdl">
      <HotelReference chainCode="AXA" hotelCode="AXAMUM" />
      <StayDateRange>
        <hc:StartDate>2013-10-01</hc:StartDate>
        <hc:EndDate>2013-10-10</hc:EndDate>
      </StayDateRange>
      <GuestCount>
        <hc:GuestCount ageQualifyingCode="ADULT" count="1" />
        <hc:GuestCount ageQualifyingCode="CHILD" count="0" />
      </GuestCount>
    </FetchCalendarRequest>
  </soap:Body>
</soap:Envelope>


    Post Url :http://000.000.000.00:8080/ows_ws_51/Availability.asmx 
Soap Action :  http://webservices.test.com/ows/5.1/Availability.wsdl#FetchCalendar
4

1 回答 1

1

看来您不必发送凭据,这会返回答案:

<?php
$soap = new SoapClient('http://webservices.micros.com/ows/5.1/Availability.wsdl', array("trace" => 1, "exception" => 0));

var_dump($soap->FetchCalendar(array(
    'StayDateRange' => array(
        'StartDate' => '2013-10-01',
        'EndDate' => '2013-10-10'
    )
)));

它仍然需要一个HotelReference艰难的。

===

以下是如何设置 SoapHeaders:

<?php
$headerbody = array('Origin' => 'foo',
                    'Destination' => 'bar');
$header = new SOAPHeader($ns, 'RequestorCredentials', $headerbody);
$soap->__setSoapHeaders($header);

有关该主题的更多信息,请参见:http: //php.net/manual/en/soapclient.setsoapheaders.php

===

这是您想要执行该方法时的soapui响应

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:core="http://webservices.micros.com/og/4.3/Core/" xmlns:ava="http://webservices.micros.com/ows/5.1/Availability.wsdl" xmlns:hot="http://webservices.micros.com/og/4.3/HotelCommon/">
   <soapenv:Header>
      <core:OGHeader transactionID="?" authToken="?" timeStamp="?" primaryLangID="E" channelValidation="true" terminalID="?">
         <core:Origin entityID="?" organizationID="?" systemType="?"/>
         <core:Destination entityID="?" organizationID="?" systemType="?"/>
         <!--Optional:-->
         <core:Intermediaries>
            <!--1 or more repetitions:-->
            <core:EndPoint entityID="?" organizationID="?" systemType="?"/>
         </core:Intermediaries>
         <!--Optional:-->
         <core:Authentication>
            <core:UserCredentials>
               <core:UserName>?</core:UserName>
               <core:UserPassword>?</core:UserPassword>
               <core:Domain>?</core:Domain>
               <!--Optional:-->
               <core:SecurityId>?</core:SecurityId>
            </core:UserCredentials>
            <!--Optional:-->
            <core:Licence>
               <!--Optional:-->
               <core:Key>?</core:Key>
            </core:Licence>
         </core:Authentication>
      </core:OGHeader>
   </soapenv:Header>
   <soapenv:Body>
      <ava:FetchCalendarRequest>
         <ava:HotelReference chainCode="?" hotelCode="?">?</ava:HotelReference>
         <ava:StayDateRange>
            <hot:StartDate>?</hot:StartDate>
            <!--You have a CHOICE of the next 2 items at this level-->
            <hot:EndDate>?</hot:EndDate>
            <hot:Duration>?</hot:Duration>
         </ava:StayDateRange>
         <!--Optional:-->
         <ava:GuestCount isPerRoom="?">
            <!--1 or more repetitions:-->
            <hot:GuestCount ageQualifyingCode="?" otherAgeQualifyingCode="?" age="?" count="?"/>
         </ava:GuestCount>
         <!--Optional:-->
         <ava:RatePlanCode>?</ava:RatePlanCode>
         <!--Optional:-->
         <ava:RoomTypeCode>?</ava:RoomTypeCode>
         <!--Optional:-->
         <ava:BlockCode>?</ava:BlockCode>
         <!--Optional:-->
         <ava:CorporateCode>?</ava:CorporateCode>
         <!--Optional:-->
         <ava:PromotionCode>?</ava:PromotionCode>
         <!--Optional:-->
         <ava:NumberOfNights>?</ava:NumberOfNights>
         <!--Optional:-->
         <ava:RestrictedMode>?</ava:RestrictedMode>
         <!--Optional:-->
         <ava:InventoryMode>?</ava:InventoryMode>
      </ava:FetchCalendarRequest>
   </soapenv:Body>
</soapenv:Envelope>

如果我将其与您的设置进行比较,您发送的选项以及您未提供 UserCredentials 的响应。这让我感觉你得到了不允许使用该方法的错误。从提供您的凭据开始。

于 2013-09-10T11:28:16.123 回答