CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1

Threaded View

  1. #1
    Join Date
    Mar 2011
    Posts
    0

    Problem with creating Web Service

    Hi,

    I'm just trying to create my first SOAP/WSDL-based Web Service in PHP. I decided to use PEAR's Services_Webservice package. That's what I coded for purpose of performing some tests (file ws.php):

    PHP Code:
    <?php
    ini_set
    ("include_path"'/home/maciek/php:' ini_get("include_path")  );
    ini_set("soap.wsdl_cache_enabled""0");

    require_once 
    'Services/Webservice.php';

    class 
    Box
    {
        
    /**
        * @var int
        */
        
    public $length 1;
        
    /**
        * @var int
        */
        
    public $width 2;
        
    /**
        * @var int
        */
        
    public $height 3;
    }

    class 
    NamedBox extends Box
    {
        
    /**
        * @var string
        */
        
    public $name "ABC";
    }

    $Boxes[1] = new Box();
    $Boxes[2] = new Box();

    class 
    ws extends Services_Webservice
    {
        
    /**
        * Some data
        */
        
    private $someData = array (
                
    'A' => array('B''C'),
                
    'X' => array('Y''Z')
                );

        
    /**
        * Getting some data
        * @param string
        * @return string[]
        */
        
    public function getsomeData($key)
        {
            
    $result = array();
            if (isset(
    $this->someData[$key]))
            {
                
    $result $this->someData[$key];
            }
            return 
    $result;
        }

        
    /**
        * Getting Boxes
        * @return Box[]
        */
        
    public function getBoxes()
        {
            return 
    $Boxes;
        }

        
    /**
        * Getting NamedBox
        * @return NamedBox
        */
        
    public function getNamedBox()
        {
            return new 
    NamedBox();
        }    
    }

    $options = array('uri' => 'ws''encoding' => SOAP_ENCODED);

    $service = new ws('ws''description'$options);

    $service->handle();
    ?>
    The next thing I'm trying to do is obtaining the WSDL file. According to PEAR's documentation, I need to add ?wsdl string to my file's URL. The problem is very strange - my service works only once! After first service call everything works fine and I'm getting WSDL file visible in my browser. But all next (after refreshing the page in web browser, and even in another web browser) calls fails... I'm getting two error messages:

    1)
    Warning: strpos() [function.strpos]: Offset not contained in string in /home/maciek/php/Services/Webservice.php on line 518

    2)
    Fatal error: Uncaught exception 'ReflectionException' with message 'Class does not exist' in /home/maciek/php/Services/Webservice.php:542 Stack trace: #0 /home/maciek/php/Services/Webservice.php(542): ReflectionClass->__construct('') #1 /home/maciek/php/Services/Webservice.php(420): Services_Webservice->classMethodsIntoStruct() #2 /home/maciek/php/Services/Webservice.php(212): Services_Webservice->intoStruct() #3 /home/maciek/public_html/noticeboard/boxes/ws.php(82): Services_Webservice->handle() #4 {main} thrown in /home/maciek/php/Services/Webservice.php on line 542

    Trying to find what is the purpose of the 2nd problem I noticed, that in PEAR's code (Webservice.php file) an empty string is putted to ReflectionClass' constructor (but not in first service call!).

    I really do not know why does it happens. I tried to put some echo instructions to print helpful messages but I didn't find a solution. The most strange thing is that over a few hours after first successful call my service starts working again - and again for only one call. Moreover, on localhost I do not have a problem... Could you help me?

    Helpful data:
    Apache 2.2.17
    PHP 5.2.12
    PEAR Services_Webservice 0.5.1 (code below)

    PHP Code:
                    for ($i 0$i count($params); ++$i) {
                        
    $_class $params[$i]->getClass();
                        
    $_type  = ($_class) ? $_class->getName() : $param[1][$i];

                        
    $_cleanType str_replace('[]'''$_type$_length);
                        
    $_typens    str_repeat('ArrayOf'$_length);

                        
    $this->wsdlStruct[$this->classname]['method'][$method->getName()]['var'][$i]['name'] =
                                
    $params[$i]->getName();
                        
    $this->wsdlStruct[$this->classname]['method'][$method->getName()]['var'][$i]['wsdltype'] =
                                
    $_typens $_cleanType;
                        
    $this->wsdlStruct[$this->classname]['method'][$method->getName()]['var'][$i]['type'] =
                                
    $_cleanType;
                        
    $this->wsdlStruct[$this->classname]['method'][$method->getName()]['var'][$i]['length'] =
                                
    $_length;
                        
    $this->wsdlStruct[$this->classname]['method'][$method->getName()]['var'][$i]['array'] =
                                (
    $_length && in_array($_cleanType$this->simpleTypes))
                                ? 
    true false;
                        
    $this->wsdlStruct[$this->classname]['method'][$method->getName()]['var'][$i]['class'] =
                                (!
    in_array($_cleanType$this->simpleTypes) && new ReflectionClass($_cleanType))
                                ? 
    true false//THAT WAS 542 line
                        
    $this->wsdlStruct[$this->classname]['method'][$method->getName()]['var'][$i]['param'] = true;
                    } 
    And that is 518 line
    $docComments_Description = trim(substr($_docComments_Description, strpos($_docComments_Description, '*') + 1, strpos($_docComments_Description, '*', 1) - 1));


    --
    Thank you in advance
    Maciek
    Last edited by PeejAvery; March 20th, 2011 at 01:50 PM. Reason: Added PHP tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured