I have created a soap server in php using the native soap server class in php. The encoding I need is ISO-8859-1
.
I have tried to do it while creating the soap server like this:
$server = new SoapServer('./AdviseAndPay.wsdl',array('encoding'=>'ISO-8859-1'));
However the encoding for the http header and the soap response is still utf-8.
I am returning a native php SoapVar
object for the soap response. I have tried setting the header Content type to ISO-8859-1
with this code:
header('Content-Type: text/xml;charset=iso-8859-1')
just before returning the SoapVar
.
However I still get the encoding as utf-8 in both the http header and the soap response.
I have tried answers in stackoverflow and in the answer the encdoding type has been set while defining the soap server but this has not worked for me.
Could you please help me. Thanks in advance.
Edit
:
This is the raw http response for the soap server response.
HTTP/1.1 200 OK
Date: Wed, 15 Jan 2014 04:47:16 GMT
Server: Apache/2.2.22 (Ubuntu)
X-Powered-By: PHP/5.4.9-4ubuntu2.4
Cache-Control: no-store, no-cache, must-revalidate, private, max-age=0
Pragma: no-cache
Expires: Wed, 11 Jan 1984 05:00:00 GMT
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 225
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/xml; charset=utf-8
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body><ns2:responseType xmlns:ns2="http://tempuri.org/response">
<code>00</code>
<message>incorrect username/password</message>
<responseBody>
<responseStr>5</responseStr>
</responseBody>
</ns2:responseType>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Edit
:
I found that there was a php bug report regarding the encoding type of the soap server response. The latest comment on that saying there was a bug was in 2008. Here is the link: php bug
Could anyone verify if they have a similar problem with soap server encoding?
Make sure you don't cache those WSDL files thats mandatory while developing.
ini_set( 'soap.wsdl_cache_enabled', '0' );
The following configuration works for me.
// Run SOAP Server
ini_set( 'soap.wsdl_cache_enabled', '0' );
$soap_config = array( 'encoding' => 'ISO-8859-1' );
$soapserver = new SoapServer( 'soap.wsdl', $soap_config );
...
// Create SOAP client
$soap_client = new SoapClient( 'soap.wsdl', array( 'encoding' => 'ISO-8859-1', 'cache_wsdl' => WSDL_CACHE_NONE) );