1

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.

Community
  • 1
  • 1
rahim asgari
  • 12,197
  • 10
  • 43
  • 53
  • What version of PHP and Zend Framework are you using? The reason I ask is because I tried a simple test without the call to `setMethod()` and I got the encoding attribute by default. I am running PHP 5.3.8 and ZF 1.12. The reason the PHP version might matter is because `Zend_Soap` and it's siblings are basically just a wrapper around PHP's native SOAP classes. – JamesG Sep 04 '13 at 05:31
  • I am using php 5.4.13 and ZF 1.12 – rahim asgari Sep 04 '13 at 12:07
  • Oh, I just realised I wasn't looking at the WSDL output, I was looking at the request and the response XML, which both contained the encoding. I have a new thought, which I will add as a potential answer to your problem. – JamesG Sep 05 '13 at 05:08

1 Answers1

2

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).

JamesG
  • 4,288
  • 2
  • 31
  • 36