客户端看起来我们在soapclient php中没有XML文档

时间:2016-01-05 21:24:56

标签: php soap client

我在php中使用SoapClient时遇到问题。考虑到我是第一次尝试验证用户凭据,因此我的代码中也可能存在一些基本错误。 我有一个简单的html标签,它获取用户凭据(在客户端)并将它们发送到处理页面(在后端工作),并使用__soapCall将soap消息发送到服务器页面。这是代码。 请帮助您提出建议

Client.php

<html>
<body>
    <form method='POST' action='middle_client.php'>
        <lable>User Name</lable><input type='text' name= 'user' id='user'>
        <br>
        <lable>Password</lable><input type='password' name= 'pass'>
        <br>
        <lable>Insurance Name</lable><input type='text' name= 'insurance'>
        <br>
        <input type='submit' name= 'submit'>

</form>
<body>
</html>

Middle_client.php

<?php 
use \SoapClient;

if(isset($_POST['submit'])){
                    $name= $_POST['user'];
                    $password= $_POST['pass'];
                    $insurance= $_POST['insurance'];

                     $con=mysql_connect("localhost","root","");
                            // Check connection

                            if (!$con) {
                               die('Not connected : ' . mysql_error());
                                }

                            $db_selected = mysql_select_db($insurance, $con);

                            if (!$db_selected) {
                                die('Invalid query: ' . mysql_error());
                            }

                            if ($db_selected=='insurance'){
                                //header('Location:server.php');
                                }

}
class client{
function __construct(){

            $parameters = array('location' => 'http://localhost/XXX/server.php', 
                                    "uri" => 'urn://localhost/XXX/',
                                    'trace' => 1,
                                );

             $this->instance = new SoapClient(NULL,$parameters);
             $auth_parameter = new stdClass();
             $auth_parameter->name = "ABC";  
             $auth_parameter->password = "root";
             $header_param = new SoapVar($auth_parameter, SOAP_ENC_OBJECT); 
             $header = new SoapHeader('XXX', 'authenticate', $header_param, false);
             $this->instance->__setSoapHeaders(array($header)); 
}


public function getname($array){
            return $this->instance->__soapCall('testing', $array);
}
}


$client = new client();
$array = array ('P_name'=> 'Foo');
echo $result = $client->getname($array);
var_dump($client);
?>

和Server.php

<?php
class server{
private $con;
public function authenticate($header_param){
                     if ($header_param->name == 'ABC' && $header_param->password == 'root' ){
                        return true;
                     }
                     else throw new SOAPFault("Wrong Name/Password", 401); 

                                 }

public function __construct(){
     $this->con = (is_null($this->con)) ? self::connect() : $this->con;
                    }

static function connect(){
                    $con=mysql_connect("localhost","root","insurance");
                            // Check connection

                            if (mysqli_connect_errno()){
                              echo "Failed to connect to MySQL: " . mysqli_connect_error();
                            }
                            $db = mysql_select_db("user", $con);
                        return $con;
} 

  public function testing($array){
    $usernme = $array['P_name'];

                            $sql = "SELECT * from user where P_name=".$usernme;
                            $qry= mysql_query($sql,$this->con);
                            $result = mysql_fetch_array($qry);

                            if (!$result) {
                                die('Invalid query: ' . mysql_error());
                            }

                            /return $returned_name= $result["P_name"];

}
}

 $parameter = array("uri" => 'localhost/XXX/server.php');
 $server = new SoapServer(NULL, $parameter);
 $server-> setClass('server');
 $server-> handle();

0 个答案:

没有答案