views:

964

answers:

5

Hi! 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&ouml;m</lastName>
     </Contact>
    </ns1:content>
   </ns1:Response>
  </ns1:callFunctionResponse>
 </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Thanks!

+2  A: 

Not sure if this will help but maybe look into HTML entities?

Phill Pafford
Thanks. I suppose it would be possible to encode everything å, ä and ö to å ä and ö respectively, but that really shouldnt be necessary.
Victor
Edit to above: As it turned out the å etc encoding was actually what broke the decoding in the first place! Dont do that when soaping! :)
Victor
+4  A: 

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?

cg
I have now :)Unfortunately it does not make any difference and also the server side logging (basic to a text file) comes out in utf-8 anyway so everything seems alright. Thanks
Victor
A: 

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.

dcousineau
I dont follow you here really... The problem is that I only can access the real data returned via __getLastResponse() - accessing it normally just gets the SOAP error.But to answer the question - yes, the soap server runs on a windows machine.
Victor
A: 

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

Victor
A: 

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.

Hexren