php的自带soap做出来的webservice和delphi交互一直产生错误。无论设置header为xml否。于是采用了nusoap,delphi可正常交互,只是产生乱码。乱码解决方法为,添加以下代码:
$server->soap_defencoding = ‘utf-8’;
$server->decode_utf8 = false;
$server->xml_encoding = ‘utf-8’;
全部示例代码如下:
<?php
// Pull in the NuSOAP code
require_once(‘common/nusoap/nusoap.php’);
// Create the server instance
$server = new soap_server();
$server->soap_defencoding = ‘utf-8’;
$server->decode_utf8 = false;
$server->xml_encoding = ‘utf-8’;
// Initialize WSDL support
$server->configureWSDL(‘hellowsdl’, ‘urn:hellowsdl’);
// Put the WSDL schema types in the namespace with the tns prefix
$server->wsdl->schemaTargetNamespace = ‘urn:hellowsdl’;
// Register the method to expose
$server->register(‘hello’, // method name
array(‘name’ => ‘xsd:string’), // input parameters
array(‘return’ => ‘xsd:string’), // output parameters
‘urn:hellowsdl’, // namespace
‘urn:hellowsdl#hello’, // soapaction
‘rpc’, // style
‘encoded’, // use
‘Says hello to the caller’ // documentation
);
// Define the method as a PHP function
function hello($name) {
if($name == ”){
return new soap_fault(‘Client’,”,’Must supply a valid name.’);
}
return ‘Hello, ‘ . $name;
}
// Use the request to (try to) invoke the service
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : ”;
$server->service($HTTP_RAW_POST_DATA);
?>
<?php// Pull in the NuSOAP coderequire_once(‘common/nusoap/nusoap.php’);// Create the server instance$server ......
查看完整文章