phpweb-serviceszend-frameworkwsdlzend-soap

zend_soap_server utf-8 encoding does not work


I am developing a soap webservice using zend_soap_server. I use Zend_Soap_AutoDiscover to auto generate wsdl of my webservice.

Here is the code

public function indexAction() { // my websrvice method

      $server = new Zend_Soap_Server("admin/webservice/wsdl");
      
      $server->setEncoding('UTF-8');

      $server->setClass('Webservice');

      $server->handle();
}

public function wsdlAction() { // my wsdl method

      $wsdl = new Zend_Soap_AutoDiscover();

      $wsdl->setClass('Webservice');

      $wsdl->setUri("/admin/webservice");

      $wsdl->handle();
}

My problem is that when i view the source of generated wsdl the first line is:

<?xml version="1.0"?>

But i want the encoding in the xml tag:

<?xml version="1.0" encoding="UTF-8"?>

What should i do to get this?

Thx in advance.


Solution

  • I checked the Zend Framework code and it would appear that the first line of the WSDL is hard-coded:

        $wsdl = "<?xml version='1.0' ?>
                <definitions name='$name' targetNamespace='$uri'
                    xmlns='http://schemas.xmlsoap.org/wsdl/'
                    xmlns:tns='$uri'
                    xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/'
                    xmlns:xsd='http://www.w3.org/2001/XMLSchema'
                    xmlns:soap-enc='http://schemas.xmlsoap.org/soap/encoding/'
                    xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/'></definitions>";
    

    The above snippet of code is from line 91 of Zend/Soap/Wsdl.php. So the simple fix to your problem is to modify the first line of the above code to include the encoding:

        $wsdl = "<?xml version='1.0' encoding='UTF-8' ?>
    

    I just ran this code and it achieved the desired outcome. And I wouldn't be too fussed about having to modify the framework code. I have a standard set of patches that I've been running over the top of ZF1 ever since about 1.7 to fix a few little oddities that I didn't agree with. That's the beauty of open source - you don't have to pay some company thousands of dollars to make a one-line change! Just make sure you remember to re-run your patch if you ever upgrade to the next maintenance release of ZF1 (assuming one comes along).