|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-06-30 09:38 UTC] ba at esoft dot dk
Description:
------------
I'm using SOAP webservices and need to send special characters (danish letters in my case) in the data, it seems these letters break the SOAP parser.
Previously we have used NuSOAP for webservices, and here special letters are encoded / decoded transparantly.
Reproduce code:
---------------
class testWebservice {
function test() {
return "???";
}
}
$SOAP = new SoapServer("test.wsdl");
$SOAP->setClass("testWebservice");
$SOAP->handle();
Expected result:
----------------
The returned string "???"
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 22:00:01 2025 UTC |
Fixed in CVS HEAD. By default ext/soap espect all string data in utf-8 encoding. Now it is possible to change internal encoding with "encoding" option. It is acceptable both by SoapClient and SoapServer. $SOAP = new SoapServer("test.wsdl", array('encoding'=>'ISO-8859-1');Hi, I tested the "encoding" option, but it doesn't work yet. In my case, I need to send/receive chinese characters in the data. So firstly I hope the SOAP data can encode with "gb2312": $SOAP = new SoapServer("test.wsdl",array('encoding'=>'gb2312')); Unfortunately, the return data is like below and "encoding" option is still 'UTF-8': HTTP/1.1 200 OK Date: Fri, 13 Aug 2004 06:42:12 GMT Server: Apache/2.0.48 (Unix) PHP/5.0.0 X-Powered-By: PHP/5.0.0 Set-Cookie: SCP_WS_SESSIONID=635131d75dc3b040f0d96e88518fe02c; path=/ Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache Content-Length: 639 Connection: close 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/" xmlns:ns1="http://xxx" xmlns:ns2="http://xxx" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <SOAP-ENV:Body> <ns1:FindDriversResponse> <FindDriversReturn SOAP-ENC:arrayType="ns2:Driver[0]" xsi:type="ns1:ArrayOf_tns1_Driver"/> </ns1:FindDriversResponse> </SOAP-ENV:Body> </SOAP-ENV:Envelope> What's the problem?I've checked with the current version (5.0.1) and it's working fine both in SoapClient and SoapServer. The problem that remains is with SoapFault. It seems it's not recognizing the enconding given before to the Server or Client Class. Here is an example: function AlteraEstado($dados) { if ($dados == 'GARBAGE') return new SoapFault("Server", "?edilha"); else return array("Answer"=>"OK"); } $server = new SoapServer("GPR.wsdl", array('encoding'=>'ISO-8859-1')); $server->addFunction(array("AlteraEstado")); $server->handle(); This code returns no valid XML Soap Envelope back to client (I suppose it breaks...).server: <?php function FindZipInfo($zipCode) { /*if($zipCode == 100021) $str = "Beijing"; else $str = "????"; return $str;*/ return $zipCode; } header("charset='GB2312'"); $server = new SoapServer("http://192.168.128.22/soap/test.wsdl", array('encoding'=>'GB2312')); $server->addFunction("FindZipInfo"); $server->handle(); ?> client:<?php try { header("charset='GB2312'"); $client = new SoapClient("http://192.168.128.22/soap/test.wsdl", array('encoding'=>'GB2312', 'trace' => 1)); $result = $client->FindZipInfo("ÖÐÎļ??Ñ??¼??Ñ??¼??Ñ??test¼??Ñ??»??¸ï´îÁ??"); //echo $client->__getLastRequest(); echo $client->__getLastResponse(); //echo $result; } catch(SoapFault $fault) { echo "SOAP Fault: (faultcode: {$fault->faultcode}, faultstring: {$fault->faultstring})"; } ?> output: <?xml version="1.0" encoding="UTF-8" ?> - <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://192.168.128.132/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> - <SOAP-ENV:Body> - <ns1:FindZipInfoResponse> <CITY xsi:type="xsd:string">???ΔΌ???????????test????????????</CITY> </ns1:FindZipInfoResponse> </SOAP-ENV:Body> </SOAP-ENV:Envelope> ~my question: why: <?xml version="1.0" encoding="UTF-8" ?>