zoukankan      html  css  js  c++  java
  • php 使用zendstudio 生成webservice文件 wsdl

    首先新建一个项目

    在项目中新建下面这些文件

    php类文件 test.php

    <?php
    class test {
        public function __construct()
        {
        }
        public function add($name,$age)
        {
            $result = array('REV'=>false);
            $result['REV'] = true;
            $result['DATA'] = 1;
            $result = json_encode($result);
            return $result;
        }
        public function del($id)
        {
            $result = false;
            return $result;
        }
        public function getlist($type)
        {
            $result = array(
                array('name'=>'张三','age'=>18),
                array('name'=>'李四','age'=>20),
                array('name'=>'jms','age'=>10),
                array('name'=>'jk陈','age'=>8),
            );
            $result = json_encode($result);
            return $result;
        }
    }
    
    ?>

    使用zendstudio生成wsdl文件

     

    生成的文件格式如下

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://localhost/t/ws" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="test_server" targetNamespace="http://localhost/t/ws">
      <wsdl:types>
        <xsd:schema targetNamespace="http://localhost/t/ws">
          <xsd:element name="getlist">
            <xsd:complexType>
              <xsd:sequence>
                <xsd:element name="in" type="xsd:string"/>
              </xsd:sequence>
            </xsd:complexType>
          </xsd:element>
          <xsd:element name="getlistResponse">
            <xsd:complexType>
              <xsd:sequence>
                <xsd:element name="out" type="xsd:string"/>
              </xsd:sequence>
            </xsd:complexType>
          </xsd:element>
        </xsd:schema>
      </wsdl:types>
      <wsdl:message name="getlistRequest">
        <wsdl:part name="type" type="xsd:int"/>
      </wsdl:message>
      <wsdl:message name="getlistResponse">
        <wsdl:part name="resultRespose" type="xsd:string"/>
      </wsdl:message>
      <wsdl:portType name="test_server">
        <wsdl:operation name="getlist">
          <wsdl:input message="tns:getlistRequest"/>
          <wsdl:output message="tns:getlistResponse"/>
        </wsdl:operation>
      </wsdl:portType>
      <wsdl:binding name="test_serverSOAP" type="tns:test_server">
          <soap:binding style="document"
              transport="http://schemas.xmlsoap.org/soap/http" />
          <wsdl:operation name="getlist">
              <soap:operation
                  soapAction="http://localhost/t/ws/NewOperation" />
              <wsdl:input>
                  <soap:body use="literal" />
              </wsdl:input>
              <wsdl:output>
                  <soap:body use="literal" />
              </wsdl:output>
          </wsdl:operation>
      </wsdl:binding>
      <wsdl:service name="test_server">
        <wsdl:port binding="tns:test_serverSOAP" name="test_serverSOAP">
          <soap:address location="http://localhost/t/ws/server.php"/>
        </wsdl:port>
      </wsdl:service>
    </wsdl:definitions>

    调用server的文件 server.php

    <?php
    ini_set("soap.wsdl_cache_enabled", "0");  //测试时打开防止soap缓存
    include("test.php");
    $Server=new SoapServer('test_server.wsdl');   //SoapServer
    $Server->setClass("test");
    $Server->handle();
    ?>

    测试调用webserver wsdl的文件

    <?php
    ini_set("soap.wsdl_cache_enabled", "0");
    //$url = 'http://localhost/t/ws/test_server.wsdl';
    $url = 'http://localhost/t/ws/server.php?wsdl';    //两种url都可以
    $client = new SoapClient($url);
    $params = array('type'=>1);
    $res = $client->__soapCall('getlist',array('parameters'=>$params));
    var_dump($res);
    ?>

    返回数据:

    string(119) "[{"name":"u5f20u4e09","age":18},{"name":"u674eu56db","age":20},{"name":"jms","age":10},{"name":"jku9648","age":8}]" 

    调用成功

  • 相关阅读:
    HTML 5 --- 移动端viewport:
    Mac Apache 启动Web工程(webserver):
    java对xml文件做增删改查------摘录
    google code 上传源码
    一段下载文件的源码
    delphi 截取指定符号之间的字符串-随机读取
    从github 读取 绝对地址 ini文件
    使用Delphi读取网络上的文本文件,html文件
    ubuntu下新立得(synaptic)软件包管理器安装
    ubuntu下卸载旧Mysql并安装新Mysql(升级)
  • 原文地址:https://www.cnblogs.com/mbailing/p/3998821.html
Copyright © 2011-2022 走看看