2012-09-26 55 views
0

我想發送肥皂請求到遠程服務器並獲取響應回。但我面臨的問題是在我的請求一個參數在我的請求,即我創建了一個參數需要我的請求,只有一個參數我不能看到,無法發送正確的參數爲XML請求使用肥皂

//示例請求:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> 
<soapenv:Body> 
<hot:HotelSearchAvailabilityReq xmlns:hot="http://www.xxx.com/schema/hotel_v17" xmlns:com="http://www.xxx.com/schema/common_v10" TargetBranch="WAB HERE"> 
<com:BillingPointOfSaleInfo OriginApplication="UDT"/> 
<hot:HotelLocation Location="TPA" LocationType="City"> 
<com:VendorLocation ProviderCode="" VendorCode="" VendorLocationID="" Key="1"/> 
<com:VendorLocation ProviderCode="" VendorCode="" VendorLocationID="" Key="2"/> 
<com:VendorLocation ProviderCode="" VendorCode="" VendorLocationID="" Key="3"/> 
<com:VendorLocation ProviderCode="" VendorCode="" VendorLocationID="" Key="2"/> 
</hot:HotelLocation> 
<hot:HotelSearchModifiers NumberOfAdults="2" NumberOfRooms="1"> 
<com:CorporateDiscountID NegotiatedRateCode="true">CCC</com:CorporateDiscountID> 
</hot:HotelSearchModifiers> 
<hot:HotelStay> 
<hot:CheckinDate>2012-06-01</hot:CheckinDate> 
<hot:CheckoutDate>2012-06-02</hot:CheckoutDate> 
</hot:HotelStay> 
</hot:HotelSearchAvailabilityReq> 
</soapenv:Body> 
</soapenv:Envelope> 

//我的要求是:

<?xml version="1.0" encoding="UTF-8"?> 
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.xxx.com/schema/common_v10" xmlns:ns2="http://www.xxx.com/schema/hotel_v19"> 
<SOAP-ENV:Body> 
    <ns2:HotelSearchAvailabilityReq> 
     <ns1:BillingPointOfSaleInfo OriginApplication="UAPI"/> 
     <ns2:HotelLocation Location="LON" LocationType="City"/> 
     <ns2:HotelSearchModifiers NumberOfAdults="2" NumberOfRooms="1"/> 
     <ns2:HotelStay> 
      <ns2:CheckinDate>2012-11-06</ns2:CheckinDate> 
      <ns2:CheckoutDate>2012-11-14</ns2:CheckoutDate> 
     </ns2:HotelStay> 
    </ns2:HotelSearchAvailabilityReq> 
</SOAP-ENV:Body> 
</SOAP-ENV:Envelope> 

在我的請求,該樣本請求,我不能夠獲取參數「VendorLocation」。

// PHP代碼: ModuleFunction.php

class HotelResultsSoapClient extends SoapClient 
{ 
function __construct($wsdlLocation) 
{ 
    $trac["trace"]=1; 
    $trac["use"]=SOAP_LITERAL; 
    $trac["style"]=SOAP_DOCUMENT; 
    $trac["compression"]=SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP | 5; 
    //$trac["compression"]=SOAP_COMPRESSION_ACCEPT ; 
    $trac["type_ns"]=""; 
    $trac["login"]=SOAP_CLIENT_USERNAME; 
    $trac["password"]=SOAP_CLIENT_PASSWORD; 
    $trac["location"]="https://xxx.com/B2BGateway/connect/uAPI/HotelService"; 
    $trac["version"]="SOAP_1_1"; 
    $trac["action"]="http://localhost:8080/kestrel/HotelService"; 

    parent::__construct($wsdlLocation,$trac); 
} 

function __doRequest($request, $location, $action, $version) 
{ 

    $namespace1="http://www.travelport.com/schema/hotel_v19_0"; 
    $namespace2="http://www.travelport.com/schema/common_v17_0"; 

    if(empty($_SESSION['hotelSearch']['nextResultReference']) || $_SESSION['hotelSearch']['nextResultReference'] == "notSet") 
    { 
    //used for sending a normal hotel request --- do not delete just comment/ uncomment 
     $request=str_replace("<ns2:HotelSearchAvailabilityReq","<ns2:HotelSearchAvailabilityReq TargetBranch=".'"'."a00000".'"'." "."xmlns:ns2=".'"'.$namespace1.'"'." "."xmlns:ns1=".'"'.$namespace2.'"',$request); 

    } 
    else 
    { 
     //used for sending next result hotel request --- do not delete just comment/ uncomment 
     $request=str_replace("<ns2:HotelSearchAvailabilityReq","<ns2:HotelSearchAvailabilityReq TargetBranch=".'"'."a00000".'"'." "."xmlns:ns2=".'"'.$namespace1.'"'." "."xmlns:ns1=".'"'.$namespace2.'"',$request); 
     $request=str_replace("<ns1:NextResultReference","<ns1:NextResultReference"." ".'ProviderCode="1G"',$request); 
    } 



    return parent::__doRequest($request, $location, $action, $version); 
}//function 

function __getLastRequestHeaders() 
{ 
    return parent::__getLastRequestHeaders(); 
}//function 

function __getLastRequest() 
{ 
    return parent::__getLastRequest(); 
}//function 

    }//class 

Results.php

require_once('ModuleFunctions.php'); 

$client = new HotelResultsSoapClient("WSDL Url"); 
$final = array(); 
$final['vc'] = {"oo","yz","hi","ii","xx"}; 
$final['vi'] = {"00000","12345","11111","99999","23456"}; 
$params = array(); 
// element = BillingPointOfsaleInfo ; attribute = OriginApplication. 
$params["BillingPointOfSaleInfo"] = array(); 
$params["BillingPointOfSaleInfo"]["OriginApplication"] = "UAPI"; 
/* ----------------------------------------------------------------------- */ 
// element = HotelLocation ; attribute = Location, LocationType. 
$params["HotelLocation"] = array(); 
$params["HotelLocation"]["Location"] = "{$destination}"; 
$params["HotelLocation"]["LocationType"] = "City"; 
/* ----------------------------------------------------------------------- */ 
// element = VendorLocation ; attribute = ProviderCode, VendorCode, VendorLocationID, Key. 
$params["VendorLocation"] = array(); 
for ($i = 0; $i < count($final['vc']); $i++) { 
$params["VendorLocation"][$i] = array(); 
$params["VendorLocation"][$i]["ProviderCode"] = "1G"; 
$params["VendorLocation"][$i]["VendorCode"] = "{$final['vc'][$i]}"; 
$params["VendorLocation"][$i]["VendorLocationID"] = "{$final['vi'][$i]}"; 
} 
//$params["VendorLocation"]["ProviderCode"] = "1G"; 
//$params["VendorLocation"]["VendorCode"] = "WV"; 
//$params["VendorLocation"]["VendorLocationID"] = "95625"; 
/* ----------------------------------------------------------------------- */ 
// element = HotelSearchModifiers ; attribute = NumberofAdults, NumberOfRooms. 
$params["HotelSearchModifiers"] = array(); 
$params["HotelSearchModifiers"]["NumberOfAdults"] = "{$NumberOfAdults}"; 
$params["HotelSearchModifiers"]["NumberOfRooms"] = "{$NumberOfRooms}"; 
/* ------------------------------------------------------------------------- */ 
// element = CorporateDiscountID ; attribute = NegotiatedRateCode. 
$params["CorporateDiscountID"] = array(); 
$params["CorporateDiscountID"]["NegotiatedRateCode"] = "true"; 
/* ------------------------------------------------------------------------- */ 
// element = HotelStay ; attribute = CheckinDate, CheckoutDate. 
$params["HotelStay"] = array(); 
$params["HotelStay"]["CheckinDate"] = "{$checkInDate}"; 
$params["HotelStay"]["CheckoutDate"] = "{$checkOutDate}"; 

$response = $client->service($params); 

echo "<hr>" . "Request" . "<hr/>" . "<br/>"; 
echo "\n" . "Request:" . htmlentities($client->__getLastRequest()) . "\n"; 
echo "<br/>"; 

我參數陣列由它,但在我請求

//參數陣列示出其:

Array 
(
[BillingPointOfSaleInfo] => Array 
    (
     [OriginApplication] => UAPI 
    ) 

[HotelLocation] => Array 
    (
     [Location] => LON 
     [LocationType] => City 
    ) 

[VendorLocation] => Array 
    (
     [0] => Array 
      (
       [ProviderCode] => 1G 
       [VendorCode] => oo 
       [VendorLocationID] => 00000 
      ) 

     [1] => Array 
      (
       [ProviderCode] => 1G 
       [VendorCode] => yz 
       [VendorLocationID] => 12345 
      ) 

     [2] => Array 
      (
       [ProviderCode] => 1G 
       [VendorCode] => hi 
       [VendorLocationID] => 11111 
      ) 

     [3] => Array 
      (
       [ProviderCode] => 1G 
       [VendorCode] => ii 
       [VendorLocationID] => 99999 
      ) 

     [4] => Array 
      (
       [ProviderCode] => 1G 
       [VendorCode] => xx 
       [VendorLocationID] => 23456 
      ) 

    ) 

[HotelSearchModifiers] => Array 
    (
     [NumberOfAdults] => 2 
     [NumberOfRooms] => 1 
    ) 

[CorporateDiscountID] => Array 
    (
     [NegotiatedRateCode] => true 
    ) 

[HotelStay] => Array 
    (
     [CheckinDate] => 2012-11-06 
     [CheckoutDate] => 2012-11-14 
    ) 

) 

任何人都可以幫助我在哪裏我錯了請。 注意:如果有更多的信息請求plz問。

此致

+0

請縮進示例請求的代碼。此外,我認爲這已經被問過,所以我建議你使用搜索。您通常不會在PHP Soap問題上看到快速答案,所以在搜索時投入一些時間值得我說。但是,您的問題最大的問題可能是,您沒有添加任何PHP代碼來設置請​​求。 **需要**,否則不清楚你的錯誤在哪裏。 – hakre

+0

添加了php代碼,並感謝提示搜索。 –

回答

0

需要只是改變參數陣列結構,作爲「vendorLocation」參數爲「HotelLocation」的一部分。所以我把Vendor location數組作爲酒店位置數組的一部分。

//參數陣列

Array 
(
[BillingPointOfSaleInfo] => Array 
    (
     [OriginApplication] => UAPI 
    ) 

[HotelLocation] => Array 
    (
     [VendorLocation] => Array 
      (
       [ProviderCode] => 1G 
       [VendorCode] => WV 
       [VendorLocationID] => 95625 
      ) 

     [Location] => LON 
     [LocationType] => City 
    ) 

[HotelSearchModifiers] => Array 
    (
     [NumberOfAdults] => 2 
     [NumberOfRooms] => 1 
    ) 

[CorporateDiscountID] => Array 
    (
     [NegotiatedRateCode] => true 
    ) 

[HotelStay] => Array 
    (
     [CheckinDate] => 2012-10-27 
     [CheckoutDate] => 2012-10-30 
    ) 

) 
+0

這是否解決了您的問題?如果這麼好看!如果您縮進示例請求,那也更明顯。如果你關心如何用PHP以編程方式縮進XML,這是一個相關的問題:[PHP的XML如何輸出很好的格式](http://stackoverflow.com/questions/8615422/php-xml-how-to-output-不錯的格式) – hakre

+0

是的,它解決了我的問題。 –

+0

請接受它作爲答案,這對未來的訪問者來說很明顯。編輯:啊,我明白了,你已經做到了! – hakre