0

I have zero experience in using SOAP and have done searching everywhere to solve this problem.

I am trying to create an XML request to send to a SOAP server from my PHP code. It's a site to get a live quotation for car insurance.

WSDL link: https://eins2.zurich.com.my/VIXAPI/VixService.svc?wsdl

I have tested using SOAPUI software and it gave me XML as below for the request:

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
   <soapenv:Header/>
   <soapenv:Body>
      <tem:fnGetVehicleDtlsByVIX>
         <!--Optional:-->
         <tem:VehInputInfo>{"AgentCode":"D02940-000","ParticipantCode":"06","RequestDateTime":"2017-Mar-17 11:00:00 PM","ID":"850321-07-5179","VehNo":"WA823H","Signature":"E448A5DE70160A7C541306B38ABAE3C8826ACD262DF217F9AA8B32244374C5E2E66D26D31874BBD832E43A6A569D20F2DFE8F674AECCFD698850BEBFB13767FD"}</tem:VehInputInfo>
      </tem:fnGetVehicleDtlsByVIX>
   </soapenv:Body>
</soapenv:Envelope>

The element VehInputInfo is the required input and is a JSON formatted string. The response was correct (via SOAPUI software, check the screenshot here) and the next step is I'm trying to pass the XML request above in my PHP code.

Below is my PHP code:

<?
// error reporting
error_reporting(E_ALL - E_NOTICE); 
ini_set('display_errors','On');

//header('Content-type: text/xml');

$wsdl = 'https://eins2.zurich.com.my/VIXAPI/VixService.svc?wsdl';

$client = new SoapClient($wsdl, array('trace'=> 1));

$xml = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
   <soapenv:Header/>
   <soapenv:Body>
      <tem:fnGetVehicleDtlsByVIX>
         <!--Optional:-->
         <tem:VehInputInfo>{"AgentCode":"D02940-000","ParticipantCode":"06","RequestDateTime":"2017-Mar-17 11:00:00 PM","ID":"850321-07-5179","VehNo":"WA823H","Signature":"E448A5DE70160A7C541306B38ABAE3C8826ACD262DF217F9AA8B32244374C5E2E66D26D31874BBD832E43A6A569D20F2DFE8F674AECCFD698850BEBFB13767FD"}</tem:VehInputInfo>
      </tem:fnGetVehicleDtlsByVIX>
   </soapenv:Body>
</soapenv:Envelope>';

//echo $xml;

try
{
    $result = $client-> fnGetVehicleDtlsByVIX($xml);
} 
catch (Exception $e)  
{
  var_dump($e->getMessage());
  var_dump($client->__getLastRequest());
  var_dump($client->__getLastResponse());
}

But all I got was errors

Am not sure if it is the correct way to create the XML or is there any other way to do this?

Anyone can help me? Thank you in advance.

5
  • have you enables SOAP? in your php.ini check phpinfo() and check SOAP is enabled there or not Commented Feb 12, 2019 at 5:45
  • I get the error "looks like we got no XML document" Commented Feb 12, 2019 at 5:45
  • @SayedMohdAli yes SOAP client & server is enabled. the wsdl is hosted on different server, by the service provider. Commented Feb 12, 2019 at 5:50
  • @Scuzzy thats the error i keep getting. dont know which part i did wrong Commented Feb 12, 2019 at 5:51
  • I see "Our site is currently undergoing scheduled maintenance and upgrades, but will be back soon" in the HTML? eins2.zurich.com.my also has a scheduled maintenance message. Commented Feb 12, 2019 at 10:24

1 Answer 1

1

I solved the problem. Changed to using cURL as below. It might not be the best answer but it solved my problem.

<?php 
// error reporting
error_reporting(E_ALL - E_NOTICE); 
ini_set('display_errors','On');

$soapUrl = "https://eins2.zurich.com.my/VIXAPI/VixService.svc?wsdl"; //URL of WSDL

// xml post structure

$xml_post_string = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
   <soapenv:Header/>
   <soapenv:Body>
      <tem:fnGetVehicleDtlsByVIX>
         <!--Optional:-->
         <tem:VehInputInfo>{"AgentCode":"D02940-000","ParticipantCode":"06","RequestDateTime":"2017-Mar-17 11:00:00 PM","ID":"850321-07-5179","VehNo":"WA823H","Signature":"E448A5DE70160A7C541306B38ABAE3C8826ACD262DF217F9AA8B32244374C5E2E66D26D31874BBD832E43A6A569D20F2DFE8F674AECCFD698850BEBFB13767FD"}</tem:VehInputInfo>
      </tem:fnGetVehicleDtlsByVIX>
   </soapenv:Body>
</soapenv:Envelope>';


$headers = array(
            "POST: https://eins2.zurich.com.my/VIXAPI/VixService.svc HTTP/1.1",
            "Content-type: text/xml;charset=\"UTF-8\"",
            "Accept-Encoding: gzip,deflate",
            "Cache-Control: no-cache",
            "Pragma: no-cache",
            "SOAPAction: \"http://tempuri.org/IVixService/fnGetVehicleDtlsByVIX\"", 
            "Content-Length: ".strlen($xml_post_string),
            "Host: eins2.zurich.com.my",
            "Connection: Keep-Alive"
        ); //SOAPAction: your op URL

$url = $soapUrl;

//print_r($headers);

// PHP cURL  for https connection with auth
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//curl_setopt($ch, CURLOPT_USERPWD, $soapUser.":".$soapPassword); // username and password - declared at the top of the doc
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string); // the SOAP request
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

// converting
$response = curl_exec($ch); 
curl_close($ch);


print_r($response);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.