php
  • web-services
  • soap
  • 2009-05-29 8 views 7 likes 
    7

    J'essaye de faire un appel non-WSDL dans PHP (5.2.5) comme ceci. Je suis sûr qu'il me manque quelque chose de simple. Cet appel a un paramètre, une chaîne, appelée "fuseau horaire":PHP Soap appel non-WSDL: comment passez-vous les paramètres?

    $URL = 'http://www.nanonull.com/TimeService/TimeService.asmx'; 
    
        $client = new SoapClient(null, array(
         'location' => $URL, 
         'uri'  => "http://www.Nanonull.com/TimeService/", 
         'trace' => 1, 
         )); 
    
    // First attempt: 
    // FAILS: SoapFault: Object reference not set to an instance of an object 
        $return = $client->__soapCall("getTimeZoneTime", 
         array(new SoapParam('ZULU', 'timezone')), 
         array('soapaction' => 'http://www.Nanonull.com/TimeService/getTimeZoneTime') 
        ); 
    
    // Second attempt: 
    // FAILS: Generated soap Request uses "param0" instead of "timezone" 
        $return = $client->__soapCall("getTimeZoneTime", 
         array('timezone'=>'ZULU'), 
         array('soapaction' => 'http://www.Nanonull.com/TimeService/getTimeZoneTime') 
        ); 
    

    Merci pour toutes suggestions
    -Dave

    Répondre

    8

    Merci. Voici l'exemple complet qui fonctionne maintenant:

    $URL = 'http://www.nanonull.com/TimeService/TimeService.asmx'; 
    
    $client = new SoapClient(null, array(
        'location' => $URL, 
        'uri'  => "http://www.Nanonull.com/TimeService/", 
        'trace' => 1, 
        )); 
    
    $return = $client->__soapCall("getTimeZoneTime", 
        array(new SoapParam('ZULU', 'ns1:timezone')), 
        array('soapaction' => 'http://www.Nanonull.com/TimeService/getTimeZoneTime') 
    ); 
    
    0

    Vous pouvez essayer d'ajouter un autre array() appel autour de votre params comme ceci:

    $params = array('timezone'=>'ZULU'); 
    $return = $client->__soapCall("getTimeZoneTime", 
        array($params), 
        array('soapaction' => 'http://www.Nanonull.com/TimeService/getTimeZoneTime') 
    ); 
    

    Je ne peux pas tester cela, mais vous pourriez.

    +0

    Essayé, mais il passe le tableau entier comme param0. Alors pas d'aller. –

    4

    Le problème se situe quelque part dans le manque d'informations sur l'espace de nommage dans le paramètre. J'ai utilisé le premier cas de votre exemple car il était le plus proche de ce que j'ai trouvé.

    Si vous modifiez la ligne:

    array(new SoapParam('ZULU', 'timezone')), 
    

    à:

    array(new SoapParam('ZULU', 'ns1:timezone')), 
    

    il devrait vous donner le résultat que vous attendiez.

    8

    La solution de Dave C ne fonctionnait pas pour moi. En regardant autour de moi est venu avec une autre solution:

    $URL = 'http://www.nanonull.com/TimeService/TimeService.asmx'; 
    
    $client = new SoapClient(null, array(
        'location' => $URL, 
        'uri'  => "http://www.Nanonull.com/TimeService/", 
        'trace' => 1, 
        )); 
    
    $return = $client->__soapCall("getTimeZoneTime", 
        array(new SoapParam(new SoapVar('ZULU', XSD_DATETIME), 'timezone')), 
        array('soapaction' => 'http://www.Nanonull.com/TimeService/getTimeZoneTime') 
    ); 
    

    Espérons que cela peut aider quelqu'un.

    Questions connexes