[PHP5] WebService über NUSOAP gibt NULL (leeres result) zurück

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • [PHP5] WebService über NUSOAP gibt NULL (leeres result) zurück

    Hallo php-ressource.de'ler

    Ich sitze jetzt, seit mittlerweile über einer halben Woche an einem Problem von meinem WebService.
    Der Service soll dazu dienen, über die Windows-COM-Api auf das WMI (WindowsManagement-Interface) zuzugreifen,
    um ein umfassendes Interface für eine SystemMonitiring-Lösung zur Verfügung stellen zu können.
    Die WMI-Query Funktion funktioniert tadellos. Mein Problem zurzeit is die Auswertung des WebService
    mittels SOAP (ich nutze NUSOAP, aber auch mit der normalen SOAP-Extension funktioniert es nicht).
    Ohne die Angabe einer WSDL-File, bekomme ich ohne Probleme meine Ergebnisse ausgeliefert, jedoch, da das ganze auch in anderen
    Programmiersprachen genutzt werden soll, ist eine WSDL unerlässlich.

    Das genaue Problem ist, dass ich ein Ergebnis zusammenstelle in meinem PHP-Script, welches relativ dynamisch ist.
    Denn meine WMI-Query-Funktion liest soviele Felder aus, wie es als Paramter übergeben kriegt und erstellt
    daraus dann ein Array. Nun kann ich dieses Array nicht genau definieren über WSDL, und ich tippe das darin auch der Fehler liegt.

    edit: irgendwie Funktionieren die PHP-Tags nicht ;(

    Hier mal alle meine Scripte mit Kommentierung:

    PHP-Code:
    <?
     
    //----> Requirements
    require_once('./lib/nusoap.php');
    //<-----


    //----> SOAP-Server

    // Server initialisieren
    $server = new soap_server();

    // Initialisiere WSDL-Support
    $server->configureWSDL('wmi', 'urn:wmi');

    // Typen hinzufügen
    $server->wsdl->addComplexType(
        'ArrayOfString',
        'complexType',
        'array',
        '',
        'SOAP-ENC:Array',
        array(),
        array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'string[]')),
        'xsd:string'
    );

    $server->wsdl->addComplexType(
        'ArrayOfArray',
        'complexType',
        'array',
        '',
        'SOAP-ENC:Array',
        array(),
        array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'ArrayOfString[]')),
        'ArrayOfString'
    );

    // Funktion registrieren
    $server->register('query_wmi',                // method name
        array('class' => 'xsd:string','fields' => 'xsd:string','where' => 'xsd:string'),        // input parameters
        array('return' => 'tns:ArrayOfArray'),      // output parameters
        'urn:wmi',                      // namespace
        'urn:wmi#query_wmi',                // soapaction
        'rpc',                                // style
        'encoded',                            // use
        'querys wmi'            // documentation
    );
    //<----


    //----> Funktion zu Abfrage des WMI

    // query_wmi('Win32_Klasse', 'Feldnamen', 'Where-Clause')
    function query_wmi($class, $fields, $where) {

         // Credentials zum Connecten einbinden
        include('./globals.php');
        
        // Wbem-COM-Object erzeugen
        $wmi = new COM('WbemScripting.SWbemLocator');    
        
        // Verbindung zum Host herstellen
        $sh = $wmi->ConnectServer($daten['host'], 'root\cimv2', $daten['user'], $daten['password']);    
        
        // Überprüfen ob eine Where-Definierung vorliegt
        if($where <> '') {
            // Mit stripslashes() die BackSlash aus der where-Clause entfernen
            $where = stripslashes($where);
            // Abfrage-String zusammensetzen und per Eval von PHP interpretieren lassen
            eval("\$eval_class = \"Select \$fields from \$class where \$where\";");
        } else eval("\$eval_class = \"Select \$fields from \$class\";");
        
        // Query senden
        $temp = $sh->ExecQuery($eval_class);
        
        // Fields zerlegen, falls mehrere Felder abgefragt werden sollen
        $array_fields = explode(", ", $fields);
        
        // Array-String leeren
        $string = '';

        // Query zerlegen
        foreach($temp as $klasse) {
            // Interpretieren des Code-Strings
            foreach($array_fields as $item) {
                if ($string == '') {
                    eval("\$string = \"'\".\$item.\"' => '\".\$klasse->\$item.\"'\";");
                } else {
                    eval("\$string = \$string.\", \".\"'\".\$item.\"' => '\".\$klasse->\$item.\"'\";");
                }
            }
            eval("\$array_temp[] = array(\\$string);");
        }
        
        return $array_temp;
    }
    //<----


    // Use the request to (try to) invoke the service
    $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
    $server->service($HTTP_RAW_POST_DATA);
        
    ?>
    PHP-Code:
    <?

    //----> Requirements
    require_once('./lib/nusoap.php');
    //<-----


    //----> SOAP-Client

    // Client initialisieren
    $client = new soapclient('http://localhost/wmi/soap_server.php?wsdl', true);

    // Check for an error
    $err = $client->getError();
    if ($err) {
        // Display the error
        echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
        // At this point, you know the call that follows will fail
    }
    // Funktionsaufruf via SOAP
    $result = $client->call('query_wmi', array('class' => 'Win32_NetworkAdapterConfiguration','fields' => 'Name','where' => ''));
    // Check for a fault
    if ($client->fault) {
        echo '<h2>Fault</h2><pre>';
        print_r($result);
        echo '</pre>';
    } else {
        // Check for errors
        $err = $client->getError();
        if ($err) {
            // Display the error
            echo '<h2>Error</h2><pre>' . $err . '</pre>';
        } else {
            // Display the result
            echo '<h2>Result</h2><pre>';
            print_r($result);
        echo '</pre>';
        }
    }
    //<----

    // Display the request and response
    echo '<h2>Request</h2>';
    echo '<pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
    echo '<h2>Response</h2>';
    echo '<pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
    // Display the debug messages
    echo '<h2>Debug</h2>';
    echo '<pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';

    ?>
    und hier noch die WSDL-File welche mir NUSOAP automatisch erstellt.
    Code:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <definitions xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" 
    xmlns:tns="urn:wmi" 
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
    xmlns="http://schemas.xmlsoap.org/wsdl/" 
    targetNamespace="urn:wmi">
    <types>
    <xsd:schema targetNamespace="urn:wmi"
    >
     <xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/" />
     <xsd:import namespace="http://schemas.xmlsoap.org/wsdl/" />
     <xsd:complexType name="ArrayOfString">
      <xsd:complexContent>
       <xsd:restriction base="SOAP-ENC:Array">
        <xsd:attribute ref="SOAP-ENC:arrayType" wsdl:arrayType="string[]"/>
       </xsd:restriction>
    
      </xsd:complexContent>
     </xsd:complexType>
     <xsd:complexType name="ArrayOfArray">
      <xsd:complexContent>
       <xsd:restriction base="SOAP-ENC:Array">
        <xsd:attribute ref="SOAP-ENC:arrayType" wsdl:arrayType="ArrayOfString[]"/>
       </xsd:restriction>
      </xsd:complexContent>
     </xsd:complexType>
    
    </xsd:schema>
    </types>
    <message name="query_wmiRequest">
      <part name="class" type="xsd:string" />
      <part name="fields" type="xsd:string" />
      <part name="where" type="xsd:string" /></message>
    <message name="query_wmiResponse">
      <part name="return" type="tns:ArrayOfArray" /></message>
    <portType name="wmiPortType">
      <operation name="query_wmi">
        <documentation>querys wmi</documentation>
    
        <input message="tns:query_wmiRequest"/>
        <output message="tns:query_wmiResponse"/>
      </operation>
    </portType>
    <binding name="wmiBinding" type="tns:wmiPortType">
      <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
      <operation name="query_wmi">
        <soap:operation soapAction="urn:wmi#query_wmi" style="rpc"/>
        <input><soap:body use="encoded" namespace="urn:wmi" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input>
        <output><soap:body use="encoded" namespace="urn:wmi" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output>
    
      </operation>
    </binding>
    <service name="wmi">
      <port name="wmiPort" binding="tns:wmiBinding">
        <soap:address location="http://localhost/wmi/soap_server.php"/>
      </port>
    </service>
    </definitions>
    ein Auszus aus der Ausgabe des Clients, was mein Problem zeigt:
    Code:
    2006-05-12 11:06:46.150814 soap_parser: in buildVal, return:
    array(1) {
      ["return"]=>
      &NULL
    }
    2006-05-12 11:06:46.151938 soap_parser: parsed successfully, found root struct: 2 of name query_wmiResponse
    2006-05-12 11:06:46.153347 soapclient: sent message successfully and got a(n) array
    return=array(1) {
      ["return"]=>
      NULL
    }
    2006-05-12 11:06:46.174303 soapclient: return shifted value: 
    NULL
    Vielen Dank für eure Hilfe.

    Mit Freundlichen Grüßen
    André Wiedemann
    Zuletzt geändert von andre_shd; 15.05.2006, 07:43.

  • #2
    hab den Fehler gefunden.
    Das Script ist vollkommen Funktionsfähig,
    es war ein kleiner Dummr Fehler in der WMI-Abfrage von seiten des Clients. ICh wollte auf ein Feld innerhalb einer win32-Klasse zugreifen, welches garnicht existiert, das gab folglich nen leeren wert aus
    Schusselfehler.

    mfg andré

    Kommentar

    Lädt...
    X