Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

return utf-8 (farsi) string from nuSOAP webservice

i wrote a very simple webservice that you can see it's code below:

SERVER :

<?php
ini_set('error_reporting', E_STRICT);
require_once("nuSOAP/lib/nusoap.php");
$namespace = "http://localhost/webservice/index.php";

// create a new soap server
$server = new soap_server();

$server->soap_defencoding = 'utf-8';
$server->decode_utf8 = false;

// configure our WSDL
$server->configureWSDL("HelloExample");

// set our namespace
$server->wsdl->schemaTargetNamespace = $namespace;

//Register a method that has parameters and return types
$server->register(
// method name:
'HelloWorld',
// parameter list:
array('name'=>'xsd:string'),
// return value(s):
array('return'=>'xsd:string'),
// namespace:
$namespace,
// soapaction: (use default)
false,
// style: rpc or document
'rpc',
// use: encoded or literal
'encoded',
// description: documentation for the method
'Simple Hello World Method');

$POST_DATA = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : '';

// pass our posted data (or nothing) to the soap service
$server->service($POST_DATA);
exit();
?>

CLIENT :

<!doctype html>
<html>
<head>
<title>Title</title>
<meta charset="utf-8"/>
</head>
<body>
<?php
require_once("nuSOAP/lib/nusoap.php");

    $client = new nusoap_client('http://localhost/webservice/index.php?wsdl');

    $client->soap_defencoding = 'UTF-8';
    $client->decode_utf8 = true;

    $err = $client->getError();
    if ($err) {
        echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
        die();
    }

    $parameters = array('name' => "محمد");

    $result = $client->call('HelloWorld', $parameters);

    if ($client->fault) {
        echo '<h2>Fault</h2><pre>';
        print_r($result);
        echo '</pre>';
        die();
    } 
    else
    {
        echo $result;
    }
?>
</body>
</html>

this Should return Hello محمد But this return Hello ????

is this unicode problem?

any help for fixing this will appreciated

like image 693
Mohammad Masoudian Avatar asked Jan 02 '14 17:01

Mohammad Masoudian


1 Answers

i fixed it myself :)

use this for Server code :

$server->soap_defencoding = 'UTF-8';
$server->decode_utf8 = false;
$server->encode_utf8 = true;

and for Client code :

$client->soap_defencoding = 'UTF-8';
$client->decode_utf8 = false;
like image 97
Mohammad Masoudian Avatar answered Nov 09 '22 14:11

Mohammad Masoudian