strange response of a webservice

Help
kermit
2011-01-21
2013-06-06
  • kermit

    kermit - 2011-01-21

    Hi,

    I'm new in nusoap.
    I'm trying to build a simple webservice: suppose to have an order of one or more items, giving the order id to webservice it answer with a list of items.

    Here is my code:

    <?php
    //includiamo la libreria NuSOAP
    require_once("../lib/nusoap/nusoap.php");
    //definiamo il nostro namespace privato come abbiamo fatto anche nel capitolo WSDL
    define("NAMESPACE", "http://localhost");
    //creiamo un istanza del server fornito da nusoap
    $server = new soap_server;
    //disattiviamo il debug
    $server->debug_flag=false;
    //cominciamo a configurare un documento WSDL (che sarà elaborato da NuSOAP) per il nostro Web service
    $server->configureWSDL('wsprova', NAMESPACE); // <-- diamo un nome al webservice ed impostiamo il nostro namespace
    $server->wsdl->schemaTargetNamespace = NAMESPACE; // <-- impostiamo il nostro namespace anche come target dello schema WSDL (come abbiamo fatto nell'esempio WSDL)
    $server->wsdl->addComplexType(
        'Product',
        'complexType',
        'struct',
        'all',
        '',
        array(
            'Name' => array('name'=>'name','type'=>'xsd:string'),
            'Code' => array('name'=>'product_number','type'=>'xsd:string'),
            'Price' => array('name'=>'price','type'=>'xsd:decimal'),
            'Ammount' => array('name'=>'quantity','type'=>'xsd:int'),
        'xx' => array('name'=>'xx','type'=>'xsd:int')                                   [b]//<===== HERE IS THE PROBLEM !!!!!!!!![/b]
        )
    );
    $server->wsdl->addComplexType(
        'ProductArray',
        'complexType',
        'array',
        '',
        'SOAP-ENC:Array',
        array(),
        array(
            array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:Product[]')
        ),
        'tns:Product'
    );
    $server->register(
       'GetProductsByCode',
       array('product_code'=>'xsd:string'),
       array('return'=>'tns:ProductArray'),
       $NAMESPACE);
    function GetProductsByCode($product_code){
        $return =array();
        $return[]=array(
            'Name' =>'a',
            'Code' => 'b',
            'Price' => '1.1',
            'Ammount' => '1',
        'xx' => '1'
        );
        
            $return[]=array(
            'Name' =>'c',
            'Code' => 'd',
            'Price' => '2.2',
            'Ammount' => '2',
            'xx' => '1'
            );
        
            
            
        return $return;
    }
    /**************************************************************************************/
    $HTTP_RAW_POST_DATA = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : '';
    $server->service($HTTP_RAW_POST_DATA);
    exit(); //non scrivere nulla sotto questa linea
    ?>
    

    I'm using soapui to test this service and in this case it give me a strance sequence of character (not an xml string).

    If I comment this line:

    'xx' => array('name'=>'xx','type'=>'xsd:int')                                   [b]//<===== HERE IS THE PROBLEM !!!!!!!!![/b]
    

    it works find !!!!

    Please can anyone help me?

    Regadrs

     
  • Scott Nichol

    Scott Nichol - 2011-01-21

    Two things came up when I tried to run the above code.

    1. define("NAMESPACE", "http://localhost")

    PHP was OK with this line, but not with subsequent lines that used NAMESPACE.  I changed NAMESPACE to MYNAMESPACE and the errors went away.

    2. $server->register(
       'GetProductsByCode',
       array('product_code'=>'xsd:string'),
       array('return'=>'tns:ProductArray'),
       $NAMESPACE);

    Notice that NAMESPACE is incorrectly referenced as a variable $NAMESPACE.  I changed this to MYNAMESPACE.

    Once I made these two changes, a simple client script was able to correctly access the service.

     
  • kermit

    kermit - 2011-01-25

    Thank you for the answer,  I made the suggested correction and now it works…but in my opinion web service output grater than 1024 byte are automatically compressed, isn't it?

     
  • kermit

    kermit - 2011-01-25

    OK I have solved my problem.
    It was about compressed response and SoapUI paramethers.

    If you got the same problem, look at soapui preference and remouve the flag on "Response compression".

    snichol Thank you for your support

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks