为 SoapServer EndPoint PHP 文件创建 WSDL 文件

Create WSDL File For SoapServer EndPoint PHP File

我想为我的 php 端点创建 wsdl 文件。 这是我的 php 终点 class 有两个功能:

class server{
private $UserIdSender;
private $UserIdReciver;
private $Title;
private $Body;
private $BoardId;
private $obj_ticket;
private $obj_ticket_owner;
private $ticket_id;
public function __construct() {
    date_default_timezone_set("Asia/Tehran");
    require_once "../../diba-modules/conf.php";
    require_once "../../diba-modules/functions.php";
    require_once "../../diba-include/entities/ticket.php";
    require_once "../../diba-include/entities/ticket_owner.php";
    $this->obj_ticket = new \entities\ticket(TRUE);
    $this->obj_ticket_owner = new \entities\ticket_owner(TRUE);
     mb_internal_encoding("UTF-8");
}           
                                                                             /*public board = 17*/
public function SaveTicketFromPortal($Token,$NationalCodeSender , $NationalCodeReciver ,   $Title , $Body = "" , $BoardId = 17  ){
    $this->UserIdSender = get_id_from_national_code($NationalCodeSender);
    $this->UserIdReciver = get_id_from_national_code($NationalCodeReciver);
    $this->Title = trim(filter_var($Title,FILTER_SANITIZE_STRING));
    $this->Body =  trim(filter_var($Body,FILTER_SANITIZE_STRING));
    $this->BoardId = filter_var($BoardId,FILTER_SANITIZE_NUMBER_INT);

    if($this->UserIdSender <= 0 ){
        return array("Success" => "-1" , "Message" => "Sender NationalCode Not Found !" );
    }elseif($this->UserIdReciver <= 0 ){
        return array("Success" => "-1" , "Message" => "Reciver NationalCode Not Found !" );
    } elseif(mb_strlen($this->Title)>500){
        return array("Success" => "-1" , "Message" => "OverFlow in Ticket Title Variable! Type Of Variable Is String(500) " );
    }elseif(mb_strlen($this->Body)>3000){
        return array("Success" => "-1" , "Message" => "OverFlow in Ticket Body Variable! Type Of Variable Is String(3000) " );
    }elseif(!is_numeric($this->BoardId) ){
        return array("Success" => "-1" , "Message" => "BoardId Should Be Number!" );
    }else{
        $this->ticket_id = $this->obj_ticket->save(NULL, $this->Title, $this->Body, $this->UserIdSender , date("Y-m-d H:i:s"), "" , 3 , 0 , $this->BoardId);
        $this->obj_ticket_owner->save(NULL, $this->ticket_id, $this->UserIdReciver, date("Y-m-d H:i:s"), 3, 0, 1);
        if($this->obj_ticket->flage && $this->obj_ticket_owner->flage){
            $this->obj_ticket->commit(TRUE);
            $this->obj_ticket_owner->commit(TRUE);
            $boardname = get_board_name($this->BoardId);
            $robot_msg = "\xF0\x9F\x93\xA2 Your Ticket Has Been Successfuly Refrenced From Portal. \n\x23\xE2\x83\xA3 $this->ticket_id \n\xF0\x9F\x93\x8B Board $boardname";
            send_with_telegram($this->UserIdReciver, $robot_msg,$this->UserIdSender);
            return array("Success" => "1" , "Message" => "Your Ticket Has Been Successfuly Refrenced." );
        }else{
            $this->obj_ticket->commit(FALSE);
            $this->obj_ticket_owner->commit(FALSE);
            return array("Success" => "-1" , "Message" => "Error In Ticket Referrals!" );
        }
    }
}
public function SaveTicketFromPortalResponse($Token){

}
} 
$params=array("uri"=>"http://127.0.0.1/board/my-webservice/portal/server.php");
$server = new SoapServer(NULL,$params);
$server->setClass("server");
$server->handle();

当我使用地址 "server.php?wsdl" 从 asp.net 调用我的 Soap 函数时,我收到如下错误: 尚不支持 WSDL 生成。! 请帮忙。 它的紧急情况。 非常感谢。

我找到了 => wsdl.php

<?php
$functions = array();    
$serviceName = "My Webservice For Recive Data From Portal";
$functions[] = array("funcName" => "SaveTicketFromPortal",
"doc" => "My Webservice For Recive Data From Portal",
"inputParams" => array(array("name" => "Token", "type" => "string"),
array("name" => "NationalCodeSender", "type" => "string"),
array("name" => "NationalCodeReciver", "type" => "string"),
array("name" => "Title", "type" => "string"),
array("name" => "Body", "type" => "string")
),
"outputParams" => array(array("name" => "Success", "type" => "string"),
array("name" => "Message" ,"type" => "string" )),
"soapAddress" => "http://192.168.10.16/board/my-webservice/portal/server.php"
);

$functions[] = array("funcName" => "SetState",
"doc" => "To Change Ticket State From Todo To Doing And Done",
"inputParams" => array(array("name" => "Token", "type" => "string"),
array("name" => "TicketId", "type" => "string"),
array("name" => "NationalCode", "type" => "string"),
array("name" => "StateId", "type" => "string")),
"outputParams" => array(array("name" => "Success", "type" => "string"),
array("name" => "Message" ,"type" => "string" )),
"soapAddress" => "http://192.168.10.16/board/my-webservice/portal/server.php"
);


if (stristr($_SERVER['QUERY_STRING'], "wsdl")) {
    // WSDL request - output raw XML
    header("Content-Type: application/soap+xml; charset=utf-8");
    echo DisplayXML();
    } else {
    // Page accessed normally - output documentation
    $cp = substr($_SERVER["SCRIPT_NAME"], strrpos($_SERVER["SCRIPT_NAME"], "/") + 1); // Current page
    echo '<!-- Attention: To access via a SOAP client use ' . $cp . '?WSDL -->';
    echo '<html>';
    echo '<head><title>' . $serviceName . '</title></head>';
    echo '<body>';
    echo '<h1>' . $serviceName . '</h1>';
    echo '<p style="margin-left:20px;">To access via a SOAP client use <code>' . $cp . '?WSDL</code></p>';

    // Document each function
    echo '<h2>Available Functions:</h2>';
    echo '<div style="margin-left:20px;">';
    for ($i=0;$i<count($functions);$i++) {
        echo '<h3>Function: ' . $functions[$i]['funcName'] . '</h3>';
        echo '<div style="margin-left:20px;">';
        echo '<p>';
        echo $functions[$i]['doc'];
        echo '<ul>';
        if (array_key_exists("inputParams", $functions[$i])) {
            echo '<li>Input Parameters:<ul>';
            for ($j=0;$j<count($functions[$i]['inputParams']);$j++) {
                echo '<li>' . $functions[$i]['inputParams'][$j]['name'];
                echo ' (' . $functions[$i]['inputParams'][$j]['type'];
            echo ')</li>';
            }
            echo '</ul></li>';
            }
            if (array_key_exists("outputParams", $functions[$i])) {
            echo '<li>Output Parameters:<ul>';
            for ($j=0;$j<count($functions[$i]['outputParams']);$j++) {
            echo '<li>' . $functions[$i]['outputParams'][$j]['name'];
            echo ' (' . $functions[$i]['outputParams'][$j]['type'];
            echo ')</li>';
            }
            echo '</ul></li>';
            }
            echo '</ul>';
            echo '</p>';
            echo '</div>';
            }
            echo '</div>';

            echo '<h2>WSDL output:</h2>';
            echo '<pre style="margin-left:20px;width:800px;overflow-x:scroll;border:1px solid black;padding:10px;background-color:#D3D3D3;">';
            echo DisplayXML(false);
            echo '</pre>';
            echo '</body></html>';
            }

            exit; 

            /*****************************************************************************
            * Create WSDL XML 
            * @PARAM xmlformat=true - Display output in HTML friendly format if set false
            *****************************************************************************/
            function DisplayXML($xmlformat=true) {
            global $functions;         // Functions that this web service supports
            global $serviceName;       // Web Service ID
            $i = 0;                    // For traversing functions array
            $j = 0;                    // For traversing parameters arrays
            $str = '';                 // XML String to output

            // Tab spacings
            $t1 = '    ';
            if (!$xmlformat) $t1 = '&nbsp;&nbsp;&nbsp;&nbsp;';
            $t2 = $t1 . $t1;
            $t3 = $t2 . $t1;
            $t4 = $t3 . $t1;
            $t5 = $t4 . $t1;

            $serviceID = str_replace(" ", "", $serviceName);

            // Declare XML format
            $str .= '<?xml version="1.0" encoding="UTF-8" standalone="no"?>' . "\n\n";

            // Declare definitions / namespaces
            $str .= '<wsdl:definitions ' . "\n"; 
            $str .= $t1 . 'xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" ' . "\n";
            $str .= $t1 . 'xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" ' . "\n";
            $str .= $t1 . 'xmlns:s="http://www.w3.org/2001/XMLSchema" ' . "\n"; 
            $str .= $t1 . 'targetNamespace="http://www.darkerwhite.com/" ' . "\n";
            $str .= $t1 . 'xmlns:tns="http://www.darkerwhite.com/" ' . "\n"; 
            $str .= $t1 . 'name="' . $serviceID . '" ' . "\n";
            $str .= '>' . "\n\n";

            // Declare Types / Schema
            $str .= '<wsdl:types>' . "\n";
            $str .= $t1 . '<s:schema elementFormDefault="qualified" targetNamespace="http://www.darkerwhite.com/">' . "\n";
            for ($i=0;$i<count($functions);$i++) {
            // Define Request Types
            if (array_key_exists("inputParams", $functions[$i])) {
            $str .= $t2 . '<s:element name="' . $functions[$i]['funcName'] . 'Request">' . "\n";
            $str .= $t3 . '<s:complexType><s:sequence>' . "\n";
            for ($j=0;$j<count($functions[$i]['inputParams']);$j++) {
            $str .= $t4 . '<s:element minOccurs="1" maxOccurs="1" ';
            $str .= 'name="' . $functions[$i]['inputParams'][$j]['name'] . '" ';
            $str .= 'type="s:' . $functions[$i]['inputParams'][$j]['type'] . '" />' . "\n"; 
            }
            $str .= $t3 . '</s:sequence></s:complexType>' . "\n";
            $str .= $t2 . '</s:element>' . "\n";
            }
            // Define Response Types
            if (array_key_exists("outputParams", $functions[$i])) {
            $str .= $t2 . '<s:element name="' . $functions[$i]['funcName'] . 'Response">' . "\n";
            $str .= $t3 . '<s:complexType><s:sequence>' . "\n";
            for ($j=0;$j<count($functions[$i]['outputParams']);$j++) {
            $str .= $t4 . '<s:element minOccurs="1" maxOccurs="1" ';
            $str .= 'name="' . $functions[$i]['outputParams'][$j]['name'] . '" ';
            $str .= 'type="s:' . $functions[$i]['outputParams'][$j]['type'] . '" />' . "\n";    
            }
            $str .= $t3 . '</s:sequence></s:complexType>' . "\n";
            $str .= $t2 . '</s:element>' . "\n";
            }       
            }
            $str .= $t1 . '</s:schema>' . "\n";
            $str .= '</wsdl:types>' . "\n\n";

            // Declare Messages
            for ($i=0;$i<count($functions);$i++) {
            // Define Request Messages
            if (array_key_exists("inputParams", $functions[$i])) {
            $str .= '<wsdl:message name="' . $functions[$i]['funcName'] . 'Request">' . "\n";
            $str .= $t1 . '<wsdl:part name="parameters" element="tns:' . $functions[$i]['funcName'] . 'Request" />' . "\n";
            $str .= '</wsdl:message>' . "\n";
            }
            // Define Response Messages
            if (array_key_exists("outputParams", $functions[$i])) {
            $str .= '<wsdl:message name="' . $functions[$i]['funcName'] . 'Response">' . "\n";
            $str .= $t1 . '<wsdl:part name="parameters" element="tns:' . $functions[$i]['funcName'] . 'Response" />' . "\n";
            $str .= '</wsdl:message>' . "\n\n";
            }
            }

            // Declare Port Types
            for ($i=0;$i<count($functions);$i++) {
            $str .= '<wsdl:portType name="' . $functions[$i]['funcName'] . 'PortType">' . "\n";
            $str .= $t1 . '<wsdl:operation name="' . $functions[$i]['funcName'] . '">' . "\n";
            if (array_key_exists("inputParams", $functions[$i])) 
            $str .= $t2 . '<wsdl:input message="tns:' . $functions[$i]['funcName'] . 'Request" />' . "\n";
            if (array_key_exists("outputParams", $functions[$i])) 
            $str .= $t2 . '<wsdl:output message="tns:' . $functions[$i]['funcName'] . 'Response" />' . "\n";
            $str .= $t1 . '</wsdl:operation>' . "\n";
            $str .= '</wsdl:portType>' . "\n\n";
            }

            // Declare Bindings
            for ($i=0;$i<count($functions);$i++) {
            $str .= '<wsdl:binding name="' . $functions[$i]['funcName'] . 'Binding" type="tns:' . $functions[$i]['funcName'] . 'PortType">' . "\n";
            $str .= $t1 . '<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />' . "\n";
            $str .= $t1 . '<wsdl:operation name="' . $functions[$i]['funcName'] . '">' . "\n";
            $str .= $t2 . '<soap:operation soapAction="' . $functions[$i]['soapAddress'] . '#' . $functions[$i]['funcName'] . '" style="document" />' . "\n";
            if (array_key_exists("inputParams", $functions[$i]))
            $str .= $t2 . '<wsdl:input><soap:body use="literal" /></wsdl:input>' . "\n";
            if (array_key_exists("outputParams", $functions[$i]))
            $str .= $t2 . '<wsdl:output><soap:body use="literal" /></wsdl:output>' . "\n";
            $str .= $t2 . '<wsdl:documentation>' . $functions[$i]['doc'] . '</wsdl:documentation>' . "\n";
            $str .= $t1 . '</wsdl:operation>' . "\n";
            $str .= '</wsdl:binding>' . "\n\n";
            }

            // Declare Service
            $str .= '<wsdl:service name="' . $serviceID . '">' . "\n";
            for ($i=0;$i<count($functions);$i++) {
            $str .= $t1 . '<wsdl:port name="' . $functions[$i]['funcName'] . 'Port" binding="tns:' . $functions[$i]['funcName'] . 'Binding">' . "\n";
            $str .= $t2 . '<soap:address location="' . $functions[$i]['soapAddress'] . '" />' . "\n";
            $str .= $t1 . '</wsdl:port>' . "\n";
            }
            $str .= '</wsdl:service>' . "\n\n";

            // End Document
            $str .= '</wsdl:definitions>' . "\n";

            if (!$xmlformat) $str = str_replace("<", "&lt;", $str); 
            if (!$xmlformat) $str = str_replace(">", "&gt;", $str);
            if (!$xmlformat) $str = str_replace("\n", "<br />", $str);
            return $str;
            }

            ?>