0

I am trying to connect to webservice using SOAP / wsdl, but I constantly get the error. I am new in soap-api in php. I have a document of api detail, it shows:

public WSGetCalendarFareResponse GetCalendarFare(WSGetCalendarFareRequest calanderFareRequest)

I made my code accordingly but still found error/exception. Please review my php code in following:

$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);
    }

When I execute my code, it returns following error:

"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

Can anyone please suggest that where problem exists? It hit & try many times but couldn't get the error point.

2 Answers 2

1

Can you debug the execution of your POST on the server side? It is heavy guessing from my side, but I assume that you do not set a mandatory value in the request, which the server needs to deserialize your object. Hence the NullReferenceException.

2
  • thankyou Seb. You are right , I made mistake in request. I have to set request value as following: $opta["GetCalendarFare"]["calanderFareRequest"]= array(); Thanks for your comment.
    – Amit Jha
    Feb 23, 2015 at 10:05
  • It would be nice then, if you could mark my answer as correct or at least up-vote it to appreciate the hint. ;) Feb 23, 2015 at 11:00
0

Problem has resolved.

The Request array should be like this:

$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
    );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.