任何人都可以帮我解决肥皂请求使用php codeigniter中的wsdl发送?

时间:2016-08-11 12:25:51

标签: wsdl

我的要求是我需要wsdl文件在php中使用SOAP请求发送xml请求,也可以从SOAP获得正确的响应。我在php中尝试过nusoap和soap类,但是我无法生成任何wsdl文件。

My server.php code as below:
<?php ini_set("soap.wsdl_cache_enabled", 0);
class Server{
    protected $class_name = '';
    public function __construct($class_name)
    {
        $this->class_name = $class_name;
    }
    public function AuthHeader($Header)
    {
        //if($Header->username == 'foo' && $Header->password == 'bar')
        //   $this->authenticated = true;
    }
    public function log($method_name,$data)
    {
        $filename = 'log.txt';
        $handle = fopen($filename, 'a+');
        fwrite($handle, date("l dS of F Y h:i:s A").' - '.$_SERVER['REMOTE_ADDR']."\r\n".$method_name."\r\n".print_r($data,true));
        fclose($handle);
    }
    public function __call($method_name, $parameters)
    {
        $this->log($method_name,$parameters); //  log
        //if($arguments[0]!=AUTH) return 'Authorization required'; // auth check
        if(!method_exists($this->class_name, $method_name )) return 'Method '.$method_name.' not found'; // methot exist check
        return call_user_func_array(array($this->class_name, $method_name ), $parameters); //call method
    }
}
class Calculator {
    public function Average ($parameters)
    {
        $num1 = $parameters->num1;
        $num2 = $parameters->num2;

        return self::AverageResponse(($num1 + $num2) / 2);
    }
    public function AverageResponse ($message)
    {
        return ['Result' => $message];
    }
}
class in {    }
$Service = new Server('Calculator');
$classmap=[
    'in' => 'in'
];
//echo '111';
$server = new SOAPServer('http://localhost/soap-websiteservice-wsdl/Calculator.wsdl', array(
    'soap_version' => SOAP_1_2,
    'style' => SOAP_RPC,
    'use' => SOAP_LITERAL,
    'classmap'=>$classmap
));
//echo '222';
$server->setObject($Service);
//$server->setClass('Calculator');
$server->handle();?>

My client.php code as below:

ini_set("soap.wsdl_cache_enabled", 0);
$options = array(
    'trace' => true
);
$client = new SOAPClient('http://localhost/soap-websiteservice-   wsdl/server.php?wsdl', $options);
#echo 'here</br>';
//var_dump($client->Average(['num1' => 10, 'num2' => 6])->Result);
$object = (object)[
 'num1' => "10",
 'num2' => "6",
];

//$req = $client->Average(['num1' => 10, 'num2' => 6]);
$req = $client->Average($object);
var_dump($req);
?>
Actually in nusoap its said that the wsdl file will be created     automatically which i don't get. i am stuck in this for so many day's now. Please reply as soon as possible

0 个答案:

没有答案