Reputation: 4239
I have a problem related to this question. I have a web service (also using php) that returns some names. When any of them contains Swedish characters (å, ä or ö) and probably others as well i get a soapfault (looks like we got no XML document). I can however see the full (correct afaik) response using $soapcalo->__getLastResponse().
How do I handle the special characters? I have tried adding the encoding attribute (utf-8) on both client and server but without success.
Edit: Excerpt of the soap reply:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="...">
<SOAP-ENV:Body>
<ns1:callFunctionResponse>
<ns1:Response>
<ns1:result>success</ns1:result>
<ns1:content>
<Contact>
<userName>VIB09SLA9EP</userName>
<firstName>Patrik</firstName>
<lastName>Stenström</lastName>
</Contact>
</ns1:content>
</ns1:Response>
</ns1:callFunctionResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Thanks!
Upvotes: 1
Views: 14601
Reputation: 109
None of these solutions worked for me. I ended overloading the SoapServer as described here:
http://blog.mayflower.de/179-Extending-class-SoapServer-PHP5-for-debugging.html
And doing a string replace in the overloaded handle function.
class OverloadedSoapServer extends SoapServer
{
public function __construct ( $wsdl, $options = null )
{
return parent::__construct ( $wsdl, $options ) ;
}
public function handle($request = null) {
$request = str_replace('&', '&', $request); // or whatever
ob_end_flush();
ob_start();
$result = parent::handle($request);
ob_flush();
return $result;
}
}
Upvotes: 0
Reputation: 101
Because I hit this question as a first result while googling 'SoapClient does not decode utf8 data correctly'
My problem was that that special chars where coming down the pipe UTF-8 encoded and php SoapClient wasn't decoding them properly.
It was fixed by changing the encoding ofthe php files in whcih my classes are to UTF-8.
Upvotes: 1
Reputation: 4239
Ok everyone - problem finally solved, thought I'd post it here for anyone else with similair problems. As it turns out, the problem occured earlier in the process.
The content of the SOAP reply was generated building the structure with a DomDocument. Later that was saved with the saveHTML function. As it turns out, that function adds some HTML encodings which breaks the soap decoding on the client.
When instead using the saveXML function the reply gets through successfully (also when adding tags and other strange stuff) and is also decoded to the correct strings by the soap client.
I hope this is the end of it, but you never know :)
Thanks for all the help and +1 on those helpful to checking the right places.
/Victor
Upvotes: 3
Reputation: 2212
Is the SOAP server a Windows based server? I've noticed that some times Windows based servers or applications will not send UTF-8
, but instead send in cp1252
.
In one app where I had special chars coming down in that encoding, I would just run the following code on my HTML output:
<?php
print htmlentities($string, ENT_COMPAT, 'cp1252');
To ensure any special characters were encoded for HTML output.
Upvotes: 0
Reputation: 3678
Just a wild guess: Have you made sure that the names actually are utf-8 encoded? I would think that just setting the SOAP attribute will noch change the actual encoding of the values. Have you tried using utf8_encode on the names before returning them via SOAP?
Upvotes: 4
Reputation: 85368
Not sure if this will help but maybe look into HTML entities?
Upvotes: 2