php soap client and soap client xml request

calling webservice from php is easy now for this we can use SoapClient object . we can do this in two ways first we will see when you have wsdl url like soap service of weather

$client = new SoapClient("https://graphical.weather.gov/xml/SOAP_server/ndfdXMLserver.php?wsdl");

$res = $client->GetWeather(array(‘CityName’ => ‘Islamabad’, ‘CountryName’ => ‘Pakistan’));
dump($res)

In second case let see how we can send xml request and use __doRequest method

$xmlreq='<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:sear="http://schemas.soa.tuimarine.com/ws/v2013_01/SearchRequest"
xmlns:com="http://schemas.soa.tuimarine.com/ws/v2013_01/CommonTypes">
<soapenv:Header/>
<soapenv:Body>
<sear:SearchRequest MaxResponses="50" Company="SUN_SAIL" Currency="GBP" Language="EN">
<sear:VoyageRequests>
<sear:VoyageRequest>
</sear:VoyageRequest>
</sear:VoyageRequests>
</sear:SearchRequest>
</soapenv:Body>
</soapenv:Envelope>';


$location_URL="https://dev.brokerapi.tuimarine.com/mar_brokerapi_ws/ws/SearchService.wsdl";
$client = new SoapClient(null, array(
    'location' => $location_URL,
    'uri'      => $location_URL,
    'trace'    => 1,
    ));
    
    try{
    $search_result = $client->__doRequest($xmlreq,$location_URL,$location_URL,1);
    //Get response from here
    print_r($search_result);
    }catch (SoapFault $exception){
    var_dump(get_class($exception));
    var_dump($exception);
    }

 

Leave a Reply

Your email address will not be published. Required fields are marked *