I am trying to create new custom SOAP API but it returns following error "SoapClient::SoapClient(): $wsdl must be string or null"

etc/webapi.xml :

<?xml version="1.0" ?>
<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Webapi:etc/webapi.xsd">
<route method="GET" url="/V1/mageplaza-helloworld/posts">
    <service class="Mageplaza\HelloWorld\Api\PostManagementInterface" method="getPost"/>
        <resource ref="anonymous"/>


  namespace Mageplaza\HelloWorld\Api;

  interface PostManagementInterface {

    public function getPost();


<?xml version="1.0" ?>
 <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Mageplaza\HelloWorld\Api\PostManagementInterface" type="Mageplaza\HelloWorld\Model\PostManagement"/>


 namespace Mageplaza\HelloWorld\Model;

 class PostManagement {

 * {@inheritdoc}
public function getPost()
    $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/custom-api.log');
    $logger = new \Zend\Log\Logger();
    $logger->info("Did't generated the session id");

    return 'api GET return the';

Api request:

    $name = array("param"=>"Jim");

    $wsdlUrl = new SoapClient("");
    $context = stream_context_create($opts);
        $soapClient = new \Zend\Soap\Client($wsdlUrl);
        $soapResponse = $soapClient->mageplazaHelloWorldPostManagementV1GetPost($name);
        echo "<pre>"; var_dump($soapResponse);
    }catch(Exception $e){
        echo "Exception Error:------".$e->getMessage();
  • It means that you WSDL route was not acceded or working, It couldn't connect to that URL. – Skatox May 23 '17 at 13:11

Your error message is referred to $soapClient = new \Zend\Soap\Client($wsdlUrl); and $wsdlUrl is not a string but a SoapClient. I mean you are using two SoapClients when you need only one.

Try to change this line:

 $wsdlUrl = new SoapClient("");

into this one:

$wsdlUrl = "";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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