2015-02-23 134 views
0

我想使用SOAP/wsdl連接到webservice,但我經常得到錯誤。我是php中的soap-api中的新成員。我有一個API文件的詳細信息,它顯示:PHP肥皂調用錯誤

public WSGetCalendarFareResponse GetCalendarFare(WSGetCalendarFareRequest calanderFareRequest) 

我相應地做了我的代碼,但仍然發現錯誤/異常。請查看我的PHP代碼如下:

$wsdl = "http://api.abc.com/xyz/service.asmx?wsdl"; // This is a test Web Service URL 
    $h = array(); 
    $opta["GetCalendarFare"]["request"]= array(
    "Origin"=>"DEL", 
    "Destination"=>"IXR", 
    "DepartureDate"=>"2015-05-01T00:00:00", 
    "ReturnDate"=>"2015-05-01T00:00:00", 
    "Type"=>"OneWay", 
    "CabinClass"=>"All", 
    "PreferredCarrier"=>"", 
    "AdultCount"=>1, 
    "ChildCount"=>1, 
    "InfantCount"=>"0", 
    "SeniorCount"=>"0", 
    "PromotionalPlanType"=>"Normal", 
    "IsDirectFlight"=>false 
    ); 

    $client_header = new SoapHeader('http://192.168.0.0/TEST/BookingAPI','AuthenticationData',$hparams,false); 
    $cliente = new SoapClient($wsdl, array('trace' => 0)); 
    $cliente->__setSoapHeaders(array($client_header)); 
    try{ 
    $h= (array)$cliente->__call('GetCalendarFare',$opta); 
    }catch(Exception $e) 
    { 
     echo '<pre>'; 
     var_dump($e); 
    } 

當我執行我的代碼,它返回以下錯誤:

"System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.NullReferenceException: Object reference not set to an instance of an object. 
    at BookingAPI.WSCalendarFareInput(WSGetCalendarFareRequest calanderFareRequest) in c:\inetpub\wwwroot\api.tektravel.com\TboApi_V7\App_Code\Service.cs:line 4544 
    at BookingAPI.GetCalendarFare(WSGetCalendarFareRequest calanderFareRequest) in c:\inetpub\wwwroot\api.tektravel.com\TboApi_V7\App_Code\Service.cs:line 4360 

任何人都可以請建議,哪裏存在問題?它嘗試多次嘗試&,但無法獲得錯誤點。

回答

1

你可以在服務器端調試POST的執行嗎?從我這邊來看,這是很沉重的猜測,但我認爲你並沒有在請求中設置一個強制值,服務器需要對你的對象進行反序列化。因此NullReferenceException

+0

三江源的Seb。你說得對,我在請求中犯了錯誤。我必須設置請求值如下:$ opta [「GetCalendarFare」] [「calanderFareRequest」] = array();謝謝你的評論。 – 2015-02-23 10:05:30

+0

如果你可以將我的答案標記爲正確或至少是贊成這一提示,那就太好了。 ;) – Seb 2015-02-23 11:00:12

0

問題已解決。

的請求陣列應該是這樣的:

$opta["GetCalendarFare"]["calanderFareRequest"]= array(
    "Origin"=>"DEL", 
    "Destination"=>"IXR", 
    "DepartureDate"=>"2015-05-01T00:00:00", 
    "ReturnDate"=>"2015-05-01T00:00:00", 
    "Type"=>"OneWay", 
    "CabinClass"=>"Economy", 
    "PreferredCarrier"=>"", 
    "AdultCount"=>1, 
    "ChildCount"=>1, 
    "InfantCount"=>"0", 
    "SeniorCount"=>"0", 
    "PromotionalPlanType"=>"Normal", 
    "IsDirectFlight"=>false 
    );