PHP Webservices SOAP, struttura file wsdl

w_t

Utente Attivo
3 Set 2007
121
0
16
Salve,
stò affrontando per la prima volta i web services SOAP in PHP, stò cercando di capire le basi e la struttura del file ".wsdl", ho trovato cosi tanti esempi e testi che non so a quale affidarmi, per ogni esempio la struttura cambia, i tag cambiano, insomma è tutto diverso...

Vi chiedo una mano per scegliere una guida dove imparare correttamente come realizzare un web services in PHP e SOAP, escludendo "nusoap e soap rest".

Se ci sono più modi di procedere vorrei imparare quello migliore a livello di sicurezza.

Grazie molte.
 

otto9due

Utente Attivo
22 Feb 2014
529
21
28
Seguo.. è un argomento che mi interessa molto e su cui ho più volte perso la testa cercando di capirci qualcosa..


Saluti G.G.
 

w_t

Utente Attivo
3 Set 2007
121
0
16
Cosa c'è di sbagliato in questo wsdl ?? Funziona ma non credo assolutamente che sia scritto come si deve.

Codice:
<?xml version="1.0" encoding="UTF-8"?>

<wsdl:definitions 
    name="Library"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    targetNamespace="Library"
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
    xmlns:tns="Library"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">

    <xsd:documentation></xsd:documentation>

    <wsdl:types>
        <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="Library">
            <xsd:complexType name="my_value">
                <xsd:sequence>
                    <xsd:element name="my_var" type="xsd:string"></xsd:element>
                </xsd:sequence>
            </xsd:complexType>
        </xsd:schema>
    </wsdl:types>

    <wsdl:message name="MyFunctionRequest">
        <wsdl:part name="_request_" type="xsd:book"></wsdl:part>
    </wsdl:message>
    <wsdl:message name="MyFunctionResponse">
        <wsdl:part name="_response_" type="tns:string"></wsdl:part>
    </wsdl:message>

    <wsdl:portType name="Library">
        <wsdl:operation name="MyFunction_1">
            <wsdl:input message="tns:MyFunctionRequest"/>
            <wsdl:output message="tns:MyFunctionResponse"/>
        </wsdl:operation>
        <wsdl:operation name="MyFunction_2">
            <wsdl:input message="tns:MyFunctionRequest"/>
            <wsdl:output message="tns:MyFunctionResponse"/>
        </wsdl:operation>
    </wsdl:portType>

    <wsdl:binding name="Library" type="tns:Library">
        <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
        <wsdl:operation name="MyFunction_1">
            <soap:operation soapAction="http://127.0.0.1/ws_soap/server.php"/>
            <wsdl:input>
                <soap:body use="literal" namespace="Library"/>
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal" namespace="Library"/>
            </wsdl:output>
        </wsdl:operation>
        <wsdl:operation name="MyFunction_2">
            <soap:operation soapAction="http://127.0.0.1/ws_soap/server.php"/>
            <wsdl:input>
                <soap:body use="literal" namespace="Library"/>
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal" namespace="Library"/>
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>

    <wsdl:service name="Library">
        <wsdl:port binding="tns:Library" name="BookLibrary">
            <soap:address location="http://127.0.0.1/ws_soap/server.php"/>
        </wsdl:port>
    </wsdl:service>

</wsdl:definitions>
Questo è il server:

Codice:
ini_set('soap.wsdl_cache_enabled', 0);

class MyClass
{
    public function MyFunction_1($my_value_1)
    {
        return $my_value_1;
    }
   
    public function MyFunction_2($my_value_2)
    {
        return $my_value_2;
    }
}

$Service = new MyClass();

$server = new SoapServer("ws.wsdl");
$server->setObject($Service);
$server->handle();
Questo è il client:

Codice:
ini_set('soap.wsdl_cache_enabled', 0);
ini_set('soap.wsdl_cache_ttl', 0);

$wsdl = 'http://127.0.0.1/ws_soap/server.php/method?WSDL';

$options = array(
                'uri'=>'http://schemas.xmlsoap.org/soap/envelope/',
                'style'=>SOAP_RPC,
                'use'=>SOAP_ENCODED,
                'soap_version'=>SOAP_1_1,
                'cache_wsdl'=>WSDL_CACHE_NONE,
                'connection_timeout'=>15,
                'trace'=>true,
                'encoding'=>'UTF-8',
                'exceptions'=>true,
                );

$objClient = new SoapClient($wsdl, $options);

try
{
    if(isset($objClient))
    {
        $resp1 = $objClient->MyFunction_1("Ciao ");
        $resp2 = $objClient->MyFunction_2(" sono Mario");
       
        echo $resp1.$resp2;
    }
}
catch(SoapFault $ex)
{
    echo var_dump($ex);
}
 

Dell Support

Nuovo Utente
30 Mag 2018
1
0
0
Codice:
<? xml version = "1.0" encoding = "UTF-8"?>

<Wsdl: definitions
    name = "Library"
    xmlns: xsd = "http://www.w3.org/2001/XMLSchema"
    targetNamespace = "Library"
    xmlns: soap = "http://schemas.xmlsoap.org/wsdl/soap/"
    xmlns: tns = "Library"
    xmlns: wsdl = "http://schemas.xmlsoap.org/wsdl/">

    <Xsd: documentation> </ xsd: documentation>

    <Wsdl: types>
        <xsd: schema xmlns: xsd = "http://www.w3.org/2001/XMLSchema" targetNamespace = "Library">
            <xsd: complexType name = "my_value">
                <Xsd: sequence>
                    <xsd: element name = "my_var" type = "xsd: string"> </ xsd: element>
                </ Xsd: sequence>
            </ Xsd: complexType>
        </ Xsd: schema>
    </ Wsdl: types>

    <wsdl: message name = "MyFunctionRequest">
        <wsdl: part name = "_ request_" type = "xsd: book"> </ wsdl: part>
    </ Wsdl: message>
    <wsdl: message name = "MyFunctionResponse">
        <wsdl: part name = "_ response_" type = "tns: string"> </ wsdl: part>
    </ Wsdl: message>

    <wsdl: portType name = "Library">
        <wsdl: operation name = "MyFunction_1">
            <wsdl: input message = "tns: MyFunctionRequest" />
            <wsdl: output message = "tns: MyFunctionResponse" />
        </ Wsdl: operation>
        <wsdl: operation name = "MyFunction_2">
            <wsdl: input message = "tns: MyFunctionRequest" />
            <wsdl: output message = "tns: MyFunctionResponse" />
        </ Wsdl: operation>
    </ Wsdl: portType>

    <wsdl: binding name = "Library" type = "tns: Library">
        <soap: binding style = "rpc" transport = "http://schemas.xmlsoap.org/soap/http" />
        <wsdl: operation name = "MyFunction_1">
            <soap: operation soapAction = "http://127.0.0.1/ws_soap/server.php" />
            <Wsdl: input>
                <soap: body use = "literal" namespace = "Library" />
            </ Wsdl: input>
            <Wsdl: output>
                <soap: body use = "literal" namespace = "Library" />
            </ Wsdl: output>
        </ Wsdl: operation>
        <wsdl: operation name = "MyFunction_2">
            <soap: operation soapAction = "http://127.0.0.1/ws_soap/server.php" />
            <Wsdl: input>
                <soap: body use = "literal" namespace = "Library" />
            </ Wsdl: input>
            <Wsdl: output>
                <soap: body use = "literal" namespace = "Library" />
            </ Wsdl: output>
        </ Wsdl: operation>
    </ Wsdl: binding>

    <wsdl: service name = "Library">
        <wsdl: port binding = "tns: Library" name = "BookLibrary">
            <soap: address location = "http://127.0.0.1/ws_soap/server.php" />
        </ Wsdl: port>
    </ Wsdl: service>

</ Wsdl: definitions>
[/ Code]

This is the server:

[Code]
ini_set ('soap.wsdl_cache_enabled', 0);

class MyClass
{
    public function MyFunction_1 ($ my_value_1)
    {
        return $ my_value_1;
    }
 
    public function MyFunction_2 ($ my_value_2)
    {
        return $ my_value_2;
    }
}

$ Service = new MyClass ();

$ server = new SoapServer ("ws.wsdl");
$ Server-> setObject ($ service);
$ Server-> handle ();
[/ Code]

This is the client:

[Code]
ini_set ('soap.wsdl_cache_enabled', 0);
ini_set ('soap.wsdl_cache_ttl', 0);

$ wsdl = 'http://127.0.0.1/ws_soap/server.php/method?WSDL';

$ options = array (
                'Uri' => 'http://schemas.xmlsoap.org/soap/envelope/',
                'Style' => SOAP_RPC,
                'Use' => SOAP_ENCODED,
                'Soap_version' => SOAP_1_1,
                'Cache_wsdl' => WSDL_CACHE_NONE,
                'Connection_timeout' => 15,
                'Trace' => true,
                'Encoding' => 'UTF-8',
                'Exceptions' => true,
                );

$ objClient = new SoapClient ($ wsdl, $ options);

try
{
    if (isset ($ objClient))
    {
        $ resp1 = $ objClient-> MyFunction_1 ("Hello");
        $ resp2 = $ objClient-> MyFunction_2 ("sono Mario");
   
        echo $ resp1. $ resp2;
    }
}
catch (SoapFault $ ex)
{
    echo var_dump ($ ex);
}
[/ Code] [/ QUOTE]
 Read this comment This is very useful, I also have a suggestion for those people who want to face the problem or do not be able to do this. simply take a help of https://dellsupports.org/ to solve the problem properly. If anyone faces any problem related to Dell they can also help.
 
Ultima modifica:

LinuxOhYeah

Utente Attivo
26 Nov 2016
188
7
18
le basi e la struttura del file ".wsdl"
Potresti iniziare con WSDL: scopriamo cos'è il Web Services Description Language uno degli articoli che trovi su https://www.mrwebmaster.it/xml/articoli/

Trovi anche: SOAP: cos'è e come funziona

Buona lettura :)

C'è anche per Android: Far dialogare la nostra app con un web service tramite WSDL e SOAP

e https://www.mrwebmaster.it/php/usare-curl-php-interagire-risorse-remote_12050.html -> Inviare dei dati nel formato JSON ad un web-service remoto
 
Ultima modifica: