PHP Nusoap - SOAP请求不起作用

Bha*_*ana 1 php web-services nusoap

您好,我是非常新的webservice,在PHP下面的代码我正在尝试制作肥皂请求,如下面的XML所示,但它说错误

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

问题:

  1. 如何传递标题?
  2. 如何使用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);
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

编辑: 工作解决方案2013年9月16日

这个解决方案只适用于Soap PHP Class我希望它能与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;
}
Run Code Online (Sandbox Code Playgroud)

qua*_*pas 7

您可以使用PHP的内置SOAP库来创建SOAP客户端并从WSDL调用方法,尝试这样的方法:

$client = new SoapClient($wsdl, array(  'soap_version' => SOAP_1_1,
                                        'trace' => true,
                                        )); 
try {
$params = array(
         //Your parameters here
          );    
$res = $client->__soapCall( 'SoapMethod', $params );
return $res;
} catch (SoapFault $e) {
echo "Error: {$e}";
}

//for debugging what the outgoing xml looks like
$client->__getLastRequest();
Run Code Online (Sandbox Code Playgroud)

WSDL应该帮助构建params的xml.如果你不能按照你想要的方式工作,你可以尝试使用SoapVar()自己传递xml 并将encode设置为XSD_ANYXML.

如果您还需要添加其他标头信息,请查看PHP文档中的此示例.