简体   繁体   中英

SOAP Client Error: “Error Fetching Http Headers”

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.

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 (eg 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM