1

I am trying to use a SOAP Client-Server in my computer and it doesn't look like it is going to work, I am getting this error Error Fetching Http Headers when I try to run my SOAP Client.

I have been looking and the solution that I have encountred is to increase the default_socket_timeout from 60 to 120 seconds and it doesn't work for me, also I have seen another solution that is putting the vhost in my apache KeepAlive Off and that didn't work.

The WSDL is working fine because I try to use it in another computer and it work.

I am running PHP Version 5.3.5-1ubuntu7.4 in Linux Mint using Zend Framework, I hope some of you can help me fix this thank you.

apz2000
  • 132
  • 6
  • 14

1 Answers1

0

I'm sorry but I don't know what you are using to set up your SOAP service.....

If you can give more information about your SOAP service (poss Zend_Soap given the Zend Framework tag) etc that would be great.

Also, as a quick alternative, you say you've looked at the WSDL on another computer, perhaps try the application in an alternative environment to ensure it's not an environment issue.

May be a simple issue with your client-server code.

UPDATE: Ok so I realised the example I mentioned yesterday wasn't fully implemented so I've hacked something together quickly that you can try to see if it works in your environment.

The code is a mix of something I found here (an example of Zend_Soap_Server) and something from another SO question here (an example of a basic SOAP service test).

I've tested it at my end using ZF 1.11 and the example I'm outlining uses the default Application path you get with a new ZF project (e.g models are in directory application/models so the model shown is headed up Application_Model_Classname).

If it works, you can tweak accordingly....if it doesn't work we can try something else. Start by creating a new SOAP controller and set the class up like this:

<?php
class SoapController extends Zend_Controller_Action
{

    public function init()
    {
        ini_set("soap.wsdl_cache_enabled", "0");     //disable WSDL caching
        $this->_helper->layout()->disableLayout();   //disable the layout
        $this->_helper->viewRenderer->setNoRender(); //disable the view
    }

    public function indexAction ()
    {
        if (isset($_GET['wsdl'])) {
            //return the WSDL
            $this->handleWSDL();
        } else {
            //handle SOAP request
            $this->handleSOAP();
        }
    }

    private function handleWSDL ()
    {
        $strategy = new Zend_Soap_Wsdl_Strategy_AnyType();
        $autodiscover = new Zend_Soap_AutoDiscover();
        $autodiscover->setComplexTypeStrategy($strategy);
        $autodiscover->setClass('Application_Model_SoapService');
        $autodiscover->handle();
    }

    private function handleSOAP ()
    {
        $server = new Zend_Soap_Server(null, 
        array('uri' => "http://YOURDOMAIN/soap?wsdl"));
        $server->setClass("Application_Model_SoapService");
        $server->handle();
    }

    public function testAction()
    {
        $client = new Zend_Soap_Client("http://YOURDOMAIN/soap?wsdl");
        try {
            echo $client->testMethod('test'); 
        } catch (Exception $e) {
            echo $e;
        }
    }

}

In the class above, the WSDL is automatically generated using Zend_Soap_Autodiscover with a SoapService.php file at application/models/SoapService.php used as the template. Note the DocBock comments above each method in your target class are integral to this process.

Next create the SoapService.php file in the default models folder:

<?php
class Application_Model_SoapService
{
    /**
    * testMethod
    *  
    * @param string $string 
    * @return string $testSuccess
    */    
    public function testMethod(string $string)
    {
        $testSuccess = 'Test successful, the message was: ' . $string;          
        return $testSuccess;
    }       

}

If all is working as it should be you can visit:

http://YOURDOMAIN/soap?wsdl

to see the WSDL and visit:

http://YOURDOMAIN/soap/test

to get a success message with the string you specified in the client request within the testAction() code in the SoapController class as part of the message.

Let me know if it's working or not and we can go from there.

I'll be able to have another look on Monday.

Community
  • 1
  • 1
dkcwd
  • 569
  • 3
  • 9
  • I use it like this: `$validate = new Zend_Soap_Client($this->getWsdlPath());` – apz2000 Jan 26 '12 at 16:19
  • Hi, I've got an example app from Zend which has a working SOAP setup with Zend Framework, I'll paste it in early next week if not beforehand (running short on time tonight. If it works ok in your environment perhaps tweak it for your needs and look at it again if need be. If you solve it in the meantime just let me know. Cheers, Dave – dkcwd Jan 27 '12 at 09:10
  • Hi, the weird thing is that this codification works in my parttner machine so I dont know why in mine doesn't work, well thanks and cheers to you too – apz2000 Jan 27 '12 at 16:51
  • 1
    Does seem strange if it's working elsewhere, if the example I've posted in the updated answer above doesn't work just let me know and we can go from there. – dkcwd Jan 28 '12 at 12:21
  • 1
    Hi, just wondering if you managed to make any progress on this issue? All the best, Dave – dkcwd Feb 03 '12 at 21:32
  • Hi, sorry I have been out of stackoverflow in this days, I am going to try that out to see if it worked, thanks a lot, Alberto – apz2000 Feb 08 '12 at 17:22
  • That's ok Alberto, let me know how you get on and if you're still having problems then we can go from there. All the best :-D – dkcwd Feb 09 '12 at 10:30
  • The weird thing about this is that I have anotherweb service but without Zend and it worked perfect, don't know if this helps, I am new in this, thanks. The best – apz2000 Feb 09 '12 at 18:40
  • No worries Alberto, have a go with the Zend example and let me know if it works. Since Zend is new for you it's probably a good idea to try a basic example like the one above and then expand on that example if you know it's working as intended. :-D – dkcwd Feb 09 '12 at 21:44
  • Hi Dave, I haven't had much time so I can't check it right now, I am going to tell you when I do it and let you know if it works or not, all the best. PD: Sorry about my english I am Mexican so it difficults me. – apz2000 Feb 15 '12 at 18:54
  • No worries Alberto, thanks for getting back to me, I'll be happy to help if you want to look at this again. :-D All the best, Dave – dkcwd Feb 19 '12 at 09:17
  • Hi Dave, thanks for your help but I don't need it anymore, I have stopped making the web service with Zend so I hope it will work, thank you anyways. – apz2000 Mar 26 '12 at 17:57