Home php教程 php手册 一个soap传输webservice框架(服务端)

一个soap传输webservice框架(服务端)

Jun 06, 2016 pm 07:32 PM
soap webservice transmission Serve frame need

需要手动在common文件夹下建立一个configure.wsdl文件 api文件夹是webservice接口。 common文件夹是常用方法、以及类库。 user/admin.php里面设置登录密码 server.php是服务端 目前wsdl在程序中自动生成 无 ?phpdate_default_timezone_set ( 'PRC' );$functio

需要手动在common文件夹下建立一个configure.wsdl文件
api文件夹是webservice接口。
common文件夹是常用方法、以及类库。
user/admin.php里面设置登录密码
server.php是服务端

目前wsdl在程序中自动生成
<?php
date_default_timezone_set ( 'PRC' );
$function = array();

require_once 'common/db.php';
require_once 'user/admin.php';
require_once 'api/Example.php';
require_once 'common/function.php';

//自动生成wsdl文件
$wsdl = "<?xml version='1.0' encoding='utf-8'?><definitions name=\"configure\" targetNamespace=\"urn:configure\" xmlns:typens=\"urn:configure\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/wsdl/soap/\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:wsdl=\"http://schemas.xmlsoap.org/wsdl/\" xmlns=\"http://schemas.xmlsoap.org/wsdl/\"><!--注册服务端请求、响应的函数和参数-->";
$message = "";
$port = "<portType name=\"serverPortType\">";
$binding = "<binding name=\"serverBinding\" type=\"typens:serverPortType\"><soap:binding style=\"rpc\" transport=\"http://schemas.xmlsoap.org/soap/http\"/>";

foreach ($function as $name => $parts){
        $message .= "<message name=\"".$name."\"><!--参数名称与类型-->";
        foreach ($parts as $part => $type){
                $message .= "<part name=\"".$part."\" type=\"xsd:".$type."\"/>";
        }
        $message .= "</message><message name=\"".$name."Response\"><part name=\"".$name."Return\" type=\"xsd:string\"/></message>";
        $port .= "<operation name=\"".$name."\"><input message=\"typens:".$name."\"/><output message=\"typens:".$name."Response\"/></operation>";
        $binding .= "<operation name=\"".$name."\"><soap:operation soapAction=\"urn:serverAction\"/><input><soap:body namespace=\"urn:configure\" use=\"encoded\" encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"/></input><output><soap:body namespace=\"urn:configure\" use=\"encoded\" encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"/></output></operation>";
        $functions[] = $name;
}
$port .= "</portType>";
$binding .= "</binding>";
$wsdl .= $message.$port.$binding."<service name=\"configureService\"><port name=\"serverPort\" binding=\"typens:serverBinding\"><soap:address location=\"http://localhost/webservice/server.php\"/></port></service></definitions>";

$file = fopen("common/configure.wsdl","w");
fwrite($file, $wsdl);
fclose($file);

$db = new db();
$service = new SoapServer('common/configure.wsdl');
$service->addFunction($functions);
$service->handle();
Copy after login
<?php
$function['admin'] = array('user' => 'string', 'pwd' => 'string');
function admin($user, $pwd){
        if ($user === 'root' && $pwd =='123456') {
                return '1';
        }else {
                return '0';
        }
}
Copy after login
<?php
defined ( 'HOST' ) || define ( 'HOST', 'localhost' );
defined ( 'USER' ) || define ( 'USER', 'XXX' );
defined ( 'PASSWORD' ) || define ( 'PASSWORD', 'XXX' );
defined ( 'DB' ) || define ( 'DB', 'XXX' );

class db{
        
        public static $_mysqli;
        public static $_stmt;
        
        /**
         * 构造函数
         */
        function __construct(){
                self::$_mysqli = new mysqli(HOST, USER, PASSWORD, DB);
                self::$_mysqli->query("set names utf8");
        }
        
        /**
         * 
         * @return boolean
         */
        function ping(){
                return self::$_mysqli->ping();
        }
        
        /**
         * 
         * @param 需要插入或者更新的参数键值对 $args
         * @return 一个字符串,需要插入或者更新的字段
         */
        private function getFields($args){
                $fields = '';
                foreach ($args as $k=>$v){
                        if ($v === '') {
                                continue;
                        }
                        $fields .= "`". $k ."`='". $v ."', ";
                }
                return substr($fields, 0, -2);
        }
        
        /**
         * 执行一条sql语句
         */
        function query($sql){
                return self::$_mysqli->query($sql);
        }
        
        /**
         * 
         * @param unknown $sql
         * @return unknown
         */
        function select($sql){
                self::$_stmt = $this->query($sql);
                if (self::$_stmt && self::$_stmt->num_rows>0) {
                        while (@$row = self::$_stmt->fetch_assoc()){
                                $res[] = $row;
                        }
                }
                self::$_stmt->free();
                return $res;
        }
        
        function get($table, $field, $where){
                $sql = "select ".$field." from ".$table." where ".$where;
                return $this->select($sql);
        }
        
        function getRow($table, $field, $where){
                $sql = "select ".$field." from ".$table." where ".$where;
                $result = $this->select($sql);
                return $result[0];
        }
        
        /**
         * 进行多条sql查询
         * @param unknown $query
         * @return mixed
         */
        function multi_query($query){
                if (self::$_mysqli->multi_query($query)){
                        do {
                                if (self::$_stmt = self::$_mysqli->store_result()) {
                                        while (@$row = self::$_stmt->fetch_row()) {
                                                $res[] = $row;
                                        }
                                        self::$_stmt->free();
                                }
                        }while (self::$_mysqli->next_result());
                }
                return $res;
        }
        
        /**
         * 向一张表插入单条记录
         * @param 即将执行插入操作的表 $table
         * @param 插入字段名和字段值的键值对 $args
         * @param 如果设置,sql语句
         * @return 插入结果
         */
        function add($table, $types, $args, $flag=false){
                if (self::$_stmt) {
                        $this->emptystmt();
                }
                $fields = "";
                $values = "";
                $bind = 'self::$_stmt->bind_param('.$types;
                foreach ($args as $k=>$v){
                        $fields .= $k.", ";
                        $values .= "?,";
                        $bind .= ' , $'.$k;
                        $$k = $v;
                }
                $bind .= ');';
                $fields = substr($fields, 0, -2);
                $values = substr($values, 0, -1);
                $sql = "insert into ".$table." (".$fields.") values (".$values.")";
                self::$_stmt = self::$_mysqli->prepare($sql);
                echo $cId;
                self::$_stmt->bind_param(iis , $cId , $pId , $createDate);
                //eval($bind);
                $res = self::$_stmt->execute();
                if ($flag) {
                        $this->emptystmt();
                }
                return $res;
        }
        
        /**
         * 向一张表删除符合条件的记录
         * @param 执行删除操作的表名 $table
         * @param 符合要求的条件 $where
         * @return 删除结果
         */
        function del($table, $where, $flag = false){
                if (self::$_stmt) {
                        $this->emptystmt();
                }
                $sql = "delete from ".$table." where ".$where;
                self::$_stmt = self::$_mysqli->prepare($sql);
                $res = self::$_stmt->execute();
                if ($flag) {
                        $this->emptystmt();
                }
                return $res;
        }
        
        /**
         * 向一张表进行更新操作
         * @param 执行更新操作的表名 $table
         * @param 插入字段名和字段值的键值对 $args
         * @param 符合要求的条件 $where
         * @return 更新结果
         */
        function update($table, $types, $args, $where, $flag = false){
                if (self::$_stmt) {
                        $this->emptystmt();
                }
                $fields = "";
                $values = "";
                $bind = 'self::$_stmt->bind_param(\''.$types.'\'';
                foreach ($args as $k=>$v){
                        $fields .= $k."=?, ";
                        $bind .= ' , $'.$k;
                        $$k = $v;
                }
                $bind .= ');';
                $fields = substr($fields, 0, -2);
                $values = substr($values, 0, -1);
                $sql = "update ".$table." set ".$fields." where ".$where;
                self::$_stmt = self::$_mysqli->prepare($sql);
                if (eval($bind)){
                        $res = self::$_stmt->execute();
                }
                if ($flag) {
                        $this->emptystmt();
                }
                return $res;
        }
        
        function bind($types, $args, $flag = false){
                if (self::$_stmt) {
                        $bind = 'self::$_stmt->bind_param('.$types;
                        foreach ($args as $k => $v){
                                $bind .= ' , $'.$k;
                                $$k = $v;
                        }
                        $bind .= ');';
                        if (eval($bind)){
                                $res = self::$_stmt->execute();
                        }
                        if ($flag) {
                                $this->emptystmt();
                        }
                        return $res;
                }
                return false;
        }
        
        /**
         * 关闭与准备语句
         */
        function emptystmt(){
                self::$_stmt->close();
        }
        
        /**
         * 析构函数
         */
        function __destruct(){
               self::$_mysqli->close();
        }
        
}
Copy after login
<?php
$function['Example'] = array('param0' => 'string', 'param1' => 'int');
function Example($param0, $param1){
        global $db;
        $info = array ($param0, $param1);
        return json_encode($info);
}
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1665
14
PHP Tutorial
1269
29
C# Tutorial
1249
24
How to evaluate the cost-effectiveness of commercial support for Java frameworks How to evaluate the cost-effectiveness of commercial support for Java frameworks Jun 05, 2024 pm 05:25 PM

Evaluating the cost/performance of commercial support for a Java framework involves the following steps: Determine the required level of assurance and service level agreement (SLA) guarantees. The experience and expertise of the research support team. Consider additional services such as upgrades, troubleshooting, and performance optimization. Weigh business support costs against risk mitigation and increased efficiency.

How does the learning curve of PHP frameworks compare to other language frameworks? How does the learning curve of PHP frameworks compare to other language frameworks? Jun 06, 2024 pm 12:41 PM

The learning curve of a PHP framework depends on language proficiency, framework complexity, documentation quality, and community support. The learning curve of PHP frameworks is higher when compared to Python frameworks and lower when compared to Ruby frameworks. Compared to Java frameworks, PHP frameworks have a moderate learning curve but a shorter time to get started.

Tsinghua Optics AI appears in Nature! Physical neural network, backpropagation is no longer needed Tsinghua Optics AI appears in Nature! Physical neural network, backpropagation is no longer needed Aug 10, 2024 pm 10:15 PM

Using light to train neural networks, Tsinghua University results were recently published in Nature! What should I do if I cannot apply the backpropagation algorithm? They proposed a Fully Forward Mode (FFM) training method that directly performs the training process in the physical optical system, overcoming the limitations of traditional digital computer simulations. To put it simply, it used to be necessary to model the physical system in detail and then simulate these models on a computer to train the network. The FFM method eliminates the modeling process and allows the system to directly use experimental data for learning and optimization. This also means that training no longer needs to check each layer from back to front (backpropagation), but can directly update the parameters of the network from front to back. To use an analogy, like a puzzle, backpropagation

How do the lightweight options of PHP frameworks affect application performance? How do the lightweight options of PHP frameworks affect application performance? Jun 06, 2024 am 10:53 AM

The lightweight PHP framework improves application performance through small size and low resource consumption. Its features include: small size, fast startup, low memory usage, improved response speed and throughput, and reduced resource consumption. Practical case: SlimFramework creates REST API, only 500KB, high responsiveness and high throughput

Golang framework documentation best practices Golang framework documentation best practices Jun 04, 2024 pm 05:00 PM

Writing clear and comprehensive documentation is crucial for the Golang framework. Best practices include following an established documentation style, such as Google's Go Coding Style Guide. Use a clear organizational structure, including headings, subheadings, and lists, and provide navigation. Provides comprehensive and accurate information, including getting started guides, API references, and concepts. Use code examples to illustrate concepts and usage. Keep documentation updated, track changes and document new features. Provide support and community resources such as GitHub issues and forums. Create practical examples, such as API documentation.

How to choose the best golang framework for different application scenarios How to choose the best golang framework for different application scenarios Jun 05, 2024 pm 04:05 PM

Choose the best Go framework based on application scenarios: consider application type, language features, performance requirements, and ecosystem. Common Go frameworks: Gin (Web application), Echo (Web service), Fiber (high throughput), gorm (ORM), fasthttp (speed). Practical case: building REST API (Fiber) and interacting with the database (gorm). Choose a framework: choose fasthttp for key performance, Gin/Echo for flexible web applications, and gorm for database interaction.

Huawei's August service day is here: free mobile phone films and free labor costs for repairs Huawei's August service day is here: free mobile phone films and free labor costs for repairs Aug 07, 2024 pm 07:24 PM

According to news on August 3, according to Huawei’s official introduction, Huawei’s July Service Day has officially started, from August 3 to August 4. It is understood that Huawei’s service days are from the first consecutive Friday to Sunday of each month (if the weekend spans the month, it will be postponed to the next weekend). Huawei users who visit the store during the event can enjoy six exclusive benefits including free film stickers and free labor costs for repairs. Specifically: Huawei mobile phones: free film, cleaning, maintenance, and system upgrade services. Huawei tablets, laptops, wearables, earphones of designated models, and smart glasses: free appearance cleaning and maintenance services. In addition, during the event, users are not required to go to the store for equipment repairs. Pay labor fees and go to the store to purchase Huawei brand accessories, extended service packages, and personalized film products: enjoy a 10% discount on the recommended retail price. The repaired equipment cannot be repaired on the same day.

Java Framework Learning Roadmap: Best Practices in Different Domains Java Framework Learning Roadmap: Best Practices in Different Domains Jun 05, 2024 pm 08:53 PM

Java framework learning roadmap for different fields: Web development: SpringBoot and PlayFramework. Persistence layer: Hibernate and JPA. Server-side reactive programming: ReactorCore and SpringWebFlux. Real-time computing: ApacheStorm and ApacheSpark. Cloud Computing: AWS SDK for Java and Google Cloud Java.

See all articles