Search code examples
phpsoapdrupal-7soap-client

Consume SOAP web service in Drupal 7


I am developing a web application in which I need to consume external web service. I looked WSClient module but some how I am not been able to use it. Is there any other way to consume external web service in Drupal 7?

Thanks, Vishal


Solution

  • Resolved this using "SoapClient" in Drupal module. Here are the steps that I followed:
    1. Download WSDL file and save this in your module folder.
    2. Using any WSDL to PHP converter, create a PHP file for the downloaded WSDL file
    3. Copy the generated PHP file in your Drupal module
    4. Include that generated PHP file in your function (within Drupal module) using following code:

    $WSDLPHPPath = drupal_get_path('module', <Module Name>) .'/< generated PHP file>.php';
    require_once($WSDLPHPPath);
    

    5.Include WSDL file using following code:

        $WSDLPath = "http://localhost/drupal/" . drupal_get_path('module', <Module Name>) .'/<Name of WSDL file>.wsdl';
        $client = new SoapClient($WSDLPath, array('location'=><Location of the WSDL file>));
    

    Here Location of the WSDL file is the server IP / name where you want to connect (e.g. http://<server name or IP>/abc?wsdl)

    6.Call your web method: (e.g. $client-><Web method name>)

    7.Refer SoapClient documentation if you want to add parameters to the web method