tags:

views:

455

answers:

2

I have a PHP SOAP server (using nuSOAP) that I consume with a C#-based application.

When the C# application submits a request, the strings are UTF-8 encoded. I verified using a network sniffer that the byte sequences are valid UTF-8. However, when PHP gets then and I post them to the database or send them by email, it appears to be printed like standard ASCII, the UTF encoding bytes are treated as characters.

I have the same issue with the C# app receiving UTF-8 from the SOAP server. .NET interprets each byte as a CHAR instead of a BYTE. I had to write a small function that converts each CHAR to a BYTE and then converts that to a UTF-8 string and that's working perfectly.

The question is, what do I need to do on the PHP server side to correctly process the incoming SOAP requests as UTF-8 for MySQL and the mail() function? I've tried utf8_encode() and utf8_decode() but those mangle the string even worse.

+1  A: 

After struggling with this all day, I found the solution.

nuSOAP was automatically running utf8_decode on incoming SOAP requests. After I disabled that feature and made sure I used mysqli->set_charset('utf8') everything appears to be working now.

Now I'd just like to know why .NET doesn't interpret the SOAP response strings properly...

Chris Thompson
A: 

You Can use
$server = new soap_server();
$server->soap_defencoding = 'UTF-8';
for decoding

neverSayNo
I was already doing that part, it was the $server->decode_utf8 = false I was missing.
Chris Thompson