您好,我对 web 服务非常陌生,在 php 中使用以下代码我正在尝试发出如下 XML 所示的肥皂请求,但它显示错误
HTTP 错误:不支持的 HTTP 响应状态 405 Method Not Allowed(soapclient->response 有响应的内容)
问题:
- 如何传递标头?
- 如何使用 XML 中的请求传递 FetchCalendarRequest?
我在这里使用过 Nusoap,但如果你有一个 SOAP PHP 类解决方案,它也会被邀请。
我的代码:
<?php
require_once('../lib/nusoap.php');
$client = new nusoap_client("http://webservices.test.com/ows/5.1/Availability.wsdl");
$err = $client->getError();
if ($err)
{
client_debug_error_message('Constructor error', $err, $client);
exit;
}
// Call the SOAP method
$result = $client->call(
'FetchCalendar',
array(
'StayDateRange' => array(
'StartDate' => '2013-10-01',
'EndDate' => '2013-10-10',
),
),
);
// Check for a fault
if ($client->fault)
{
debug_preformatted('Fault', $result);
}
else
{
// Check for errors
$err = $client->getError();
if ($err)
{
debug_preformatted('Error', $err);
}
else
{
debug_preformatted('Result', $result);
}
}
// Display the request and response
client_debug_dump($client);
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
编辑: 工作解决方案 2013 年 9 月 16 日
此解决方案仅适用于 Soap PHP 类,我希望它与 Nusoap 弓一起使用。
<?php
$wsdl = "http://###.###.###.##:8080/ows_ws_51/Availability.asmx?wsdl";
$client = new SoapClient($wsdl, array( 'soap_version' => SOAP_1_1,'trace' => true,));
//=========== Header Setting ============
$ns = 'http://webservices.micros.com/og/4.3/Availability/'; //Namespace of the WS.//Body of the Soap Header.
$strHeaderComponent_Session = <<<XML
<OGHeader transactionID="005435" timeStamp="2008-12-09T13:26:56.4056250-05:00" xmlns="http://webservices.micros.com/og/4.3/Core/">
<Origin entityID="OWS" systemType="WEB" />
<Destination entityID="WEST" systemType="ORS" />
</OGHeader>
XML;
$objVar_Session_Inside = new SoapVar($strHeaderComponent_Session, XSD_ANYXML, null, null, null);
$objHeader_Session_Outside = new SoapHeader($ns , 'SessionHeader', $objVar_Session_Inside);
// More than one header can be provided in this array.
$client->__setSoapHeaders(array($objHeader_Session_Outside));
//============== Request ================
$xml = <<<XML
<FetchCalendarRequest xmlns:a="http://webservices.micros.com/og/4.3/Availability/" xmlns:hc="http://webservices.micros.com/og/4.3/HotelCommon/" xmlns="http://webservices.micros.com/ows/5.1/Availability.wsdl">
<HotelReference chainCode="AXA" hotelCode="{$DdlHotels}" />
<StayDateRange>
<hc:StartDate>{$Arrive}</hc:StartDate>
<hc:EndDate>{$Depart}</hc:EndDate>
</StayDateRange>
<GuestCount>
<hc:GuestCount ageQualifyingCode="ADULT" count="1" />
<hc:GuestCount ageQualifyingCode="CHILD" count="0" />
</GuestCount>
</FetchCalendarRequest>
XML;
$args = array(new SoapVar($xml, XSD_ANYXML));
try
{
$response = $client->__soapCall( 'FetchCalendar', $args );
}
catch (SoapFault $e)
{
echo "Error: {$e}"; exit;
}