PHP SOAP请求无法正常工作

时间:2013-09-10 11:12:09

标签: php soap

您好我是webservice的新手,在php中使用以下代码我正在尝试制作肥皂请求,如下面的XML所示,但它说 的错误

HTTP错误:不支持的HTTP响应状态405方法不允许(soapclient->响应包含响应内容)

Q值。 1)如何传递标题 2)如何传递FetchCalendarRequest

我在这里使用了nusoap但是如果你有肥皂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

1 个答案:

答案 0 :(得分: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。这让我感觉你得到的错误是你不允许使用那种方法。首先提供您的凭据。