SOAP-ERROR: Parsing WSDL

If you’re writing or consuming webservices with PHP SOAP, it’s possible you run into the SOAP-ERROR: Parsing WSDL problem once.

The complete error string is:
SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://host/service?wsdl' : <specific error>

If you copy and paste the url (including the ?wsdl parameter) in the browser and you see the WSDL file, the problem lies in the fact that the PHP cannot reach the host.

When you connect to http://host/service, PHP fetches the XML from the WSDL page via fopen(‘http://host/service?wsdl‘) so it can use it to handle the request. In some cases, that request is not routed correct, resulting in the SOAP-ERROR.

Some solutions:

  • Add the hostname in the hostfile of the server (127.0.0.1 hostname).
  • Add the hostname or IP address in the correct VirtualHost (ServerAlias hostname).

You can test the code by adding a file on the server:

<?php
echo htmlentities(file_get_contents('http://host/service?wdsl'));

That way, you know if the server can reach and read the XML file.

  • Larry

    I have same problem. XML from URL displays correctly in browser. I am trying to access localhost SSRS webservice. http://localhost:8080/ReportServer displays correctly. But calling the following fails with same error string you have posted.

    $client = new SoapClient(“http://localhost:8080/ReportServer/ReportExecution2005.asmx?wsdl”,
    array(‘login’ => “domain\userid”,
    ‘password’ => “password”));

    My environment: Windows 7, XAMPP, PHP 5.4.7.

    Problem is I don’t know if how I am setting up the virtual host on XAMPP is correct. This is what I did:

    NameVirtualHost *

    DocumentRoot “C:\xampp\htdocs\SBSProductionDatabase”
    ServerName localhost

    DocumentRoot “C:\Program Files\Microsoft SQL Server\MSRS10_50.MSSQLSERVER\Reporting Services\ReportServer”
    ServerName localhost:8080/ReportServer

    Order allow,deny
    Allow from all

  • @Larry I don’t know much about consuming Microsoft SOAP, but these are the “errors” I see:

    You have two blocks DocumentRoot and ServerName (this is not a problem, because it will only use the last one).

    In ServerName, you cannot use a path (/ReportServer). You should do this:

    DocumentRoot “C:\Program Files\Microsoft SQL Server\MSRS10_50.MSSQLSERVER\Reporting Services”
    ServerName localhost:8080

  • Mark Jann

    Great post. You save my day!