Documentation

CWebServiceDesc

Web service diagram

CWebServiceDesc members

Parameter Type Description
wsname string The name of a web service (e.g. bitrix.ws.users).
wsclassname string The class that implements a web service and IWebService.
wsdlauto boolean Specifies whether the WSDL code is to be generated automatically.
wstargetns string A namespace (e.g. http://bitrix.ru/)
wsendpoint string A web service access point (e.g. http://bitrix.ru/ws/testws.php).
classes array An array describing the web service methods.
structTypes array An array describing complex data types (structures) of a web service.
classTypes array Describes complex types of data deserialized from XML to class instances.

The CWebServiceDesc class (web service descriptor) must be fully initialized. This class is returned by IWebService::GetWebServiceDesc. After the web service descriptor has been registered, instances of a SOAP server and a WSDL generator are created in it.

Web service methods

Web service methods always:

  • belong to a class that implements a web service;
  • fully describe both input and output parameters;
  • maintain types of input and output parameters according to their description.

Data types

Web server methods can use the following data types:

  • Simple types: string, bool, boolean, int, integer, double, float, number;
  • Complex types: arrays, structures (can be serialized to associated arrays), classes (can be serialized to class instances). They can be described using structTypes, classTypes.

Data types are defined in the following sections of CWebServiceDesc:

  • classes - arrays as method parameters (see Web Service Classes);
  • structTypes - structures;
  • classTypes - classes.

Web service description

If WSDL is generated automatically, Document/Literal binding is also generated. A SOAP server can support only Document/Literal binding. The XSD schema is generated for all types and parameters.

Parameter Description
classes This class member must be initialized. It defines web service methods via the class, input and output parameters. Arrays (as complex data types) can be used if attributes arrType and varType are specified. A corresponding data type is automatically created in the XSD shema.

Associated array:
$wsdesc->classes = array(
    "web service class with methods" => array(
        "web service method" => array(
            // method is public
            "type"        => "public",                        
            "name"        => "web service method",
            // method parameters
            // "strict" => "no" means the parameter is not required;
            // and can be omitted in a soap request. "input" => array( // "DataType" - name of a complex or simple data type "ParameterName" =>array("varType" => "DataType"[, "strict" => "no"]),
// Array parameters: // varType - array name (data type for xsd schema) // arrType - array element typeа "ParameterName" =>array("varType" => "ArrayOf"."DataType", "arrType" => "DataType"),
// Example of complex data types. // Complex types must be defined in structTypes, classTypes "ParameterName" =>array("varType" => "sGenTest"),
// Example of passing complex array "ParameterName" =>array("varType" => "ArrayOfSGenTest", "arrType" => "sGenTest") ... // Output parameeters "output" => array( // only one output parameter can be defined "user" => array("varType" => "DataType") ), // whether HTTP Basic authorisation is required. "httpauth" => "Y или N" ), ... ), ... );
structTypes Defines structured data types (associated arrays in PHP; structures and classes in VisualStudio). A SOAP server deserilizes these types to associated arrays.

Names of data types can be used in web service method parameter declarations (in classes). "ComplexType" is automatically created for these data types in the XSD schema.

Associated array:
$wsdesc->structTypes["StructureName"] =
    array(
        "FieldName" => array("varType" => "DataType"),
        ...
    );
classTypes Defines classes as data types. They are represented as classes in PHP and VisualStudio. A SOAP server deserializes these types to instances of defined classes. A class must be defined before it can be deserialized.

Names of data types can be used in web service method parameter declarations (in classes). "ComplexType" is automatically created for these data types in the XSD schema.

Associated array:
$wsdesc->classTypes["ClassName"] =
    array(
        "FieldName" => array("varType" => "DataType"),
        ...
    );

Example


You can find a good example of using CWebServiceDesc in \bitrix\modules\webservice\classes\general\webservice.wsdl.phpt:


class CCheckAuthWS extends IWebService
{
    ...

    function GetWebServiceDesc() 
    {
        $wsdesc = new CWebServiceDesc();
        $wsdesc->wsname = "bitrix.webservice.checkauth";
        $wsdesc->wsclassname = "CCheckAuthWS";
        $wsdesc->wsdlauto = true;
        $wsdesc->wsendpoint = CWebService::GetDefaultEndpoint();
        $wsdesc->wstargetns = CWebService::GetDefaultTargetNS();
        
        $wsdesc->classTypes = array();
        $wsdesc->structTypes["CUser"] =
        array(
            "ID" => array("varType" => "integer"),
            "NAME" => array("varType" => "string"),
            "TIMESTAMP_X" => array("varType" => "string"),
            "LOGIN" => array("varType" => "string"),
            "PASSWORD" => array("varType" => "string"),
            "CHECKWORD" => array("varType" => "string"),
            "ACTIVE" => array("varType" => "string"),
            "LAST_NAME" => array("varType" => "string"),
            "EMAIL" => array("varType" => "string")        
        );
        
        $wsdesc->classes = array(
            "CCheckAuthWS" => array(
                "CheckAuthorization" => array(
                    "type"        => "public",
                    "name"        => "CheckAuthorization",
                    "input"        => array(
                        "user" =>array("varType" => "string"),
                        "password" =>array("varType" => "string")),
                    "output"    => array(
                        "user" => array("varType" => "CUser")
                        )
                ),
            "GetHTTPUserInfo" => array(
                    "type"        => "public",
                    "name"        => "GetHTTPUserInfo",
                    "input"        => array(),
                    "output"    => array(
                        "user" => array("varType" => "CUser")
                        ),
                    "httpauth" => "Y"
                )
            )
        );
        
        return $wsdesc;
    }
    
    ...
}
© «Bitrix24», 2001-2024
Up