1

I'm trying to output "Hello World" using XML but I'm getting the following exception in my php page:

Fatal error: Uncaught SoapFault exception: [HTTP] Error Fetching http headers in C:\wamp\www\Web_Service\SampleXML\index.php:4 Stack trace:
#0 [internal function]: SoapClient->_doRequest('<?xml version="...', 'http://localhos...', 'urn:localhost-s...', 1, 0)
#1 [internal function]: SoapClient->
_call('getHelloWorld', Array)
#2 C:\wamp\www\Web_Service\SampleXML\index.php(4): SoapClient->getHelloWorld()
#3 {main} thrown in C:\wamp\www\Web_Service\SampleXML\index.php on line 4

index.php

<?php
    $client = new SoapClient('service.wsdl');
    $response = $client->getHelloWorld(); 
    echo $response;
?>

service.wsld

<?xml version = '1.0' encoding = 'UTF-8' ?>

<definitions name = "Web Service"
    targetNamespace = 'http://example.org/service'
    xmlns:tns = 'http://example.org/service'
    xmlns:soap = 'http://schemas.xmlsoap.org/wsdl/soap/'
    xmlns:xsd = 'http://www.w3.org/2001/XMLSchema'
    xmlns:soapenc = 'http://schemas.xmlsoap.org/soap/encoding/'
    xmlns:wsdl = 'http://schemas.xmlsoap.org/wsdl/'
    xmlns = 'http://schemas.xmlsoap.org/wsdl/' >

    <!-- Message -->
    <message name='getHelloWorld'>
        <part name='response' type='xsd:string' />
    </message>

    <!-- Operations offered -->
    <portType name = 'PortType'>
        <operation name = 'getHelloWorld'>
                <!-- Target Name Space -->
                <output message = 'tns:getHelloWorld' />
        </operation>
    </portType>

    <!-- Binding Element -->
    <binding name = 'Binding' type = 'tns:PortType'>
        <soap:binding style='rpc' transport='http://schemas.xmlsoap.org/soap/http' />
        <operation name='getHelloWorld'>
            <soap:operation soapAction = 'urn:localhost-service#getHelloWorld' />

        <!-- Output -->
        <output>
            <soap:body use='encoded' namespace='urn:locahost-service' encodingStyle='http://schemas.xmlsoap.org/soap/encoding/' />
        </output>
        </operation>
    </binding>

    <!-- Define the service -->
    <service name='Service'>
        <port name='Port' binding='Binding' >
            <!-- Location -->
            <soap:address location='http://localhost/Web_Service/SampleXML/soap-server.php' />
        </port>
    </service>

</definitions>

soap-server.php

<?php

    function getHelloWorld() {
        return "Hello World";
    }

    ini_set("soap.wsdl_cache_enabled", "0");

    $server = new SoapServer('service.wsdl');
    $server->addFunction("getHelloWorld");    
    $server->handle();

?>

Did I miss something in the code?

6
  • if you just call soap-server.php directly it has any errors? Commented Jan 7, 2013 at 9:08
  • no errors. just a blank page. Commented Jan 7, 2013 at 9:24
  • and when you view source do you see any output? Commented Jan 7, 2013 at 9:25
  • no output in the source code. Commented Jan 7, 2013 at 9:58
  • 1
    maybe then your soapserver is not getting initialized, add some exception handling or a simple check if it is being created? Commented Jan 7, 2013 at 10:00

4 Answers 4

4

try to set this line,

ini_set("default_socket_timeout", 200);

or put this in php.ini

 default_socket_timeout = 200
3

I suppose it's too late, but I have the same problem. I try the socket timeout but it doesn't work. My problem was that the client and the server where in the same physical server. With the client code working in the same physical server , I get this error, but, with the same client code moved to my localhost, requesting the server, (client and server was executed in two differents mechines) all works fine.

Maybe that can help someone else!

1

I had this problem with intensive SOAP calls, the solution swich off KeepAlive in httpd.conf in apache.

Add KeepAlive Off to httpd.conf and restart apache.

0

I just want to report that this error is triggered when you try to connect to a server and this server replies with invalid data or does not reply at all.

Increasing the timeout could be helpful but only in the context that the server is taking too long to reply, as said you can increase the value in php.ini

default_socket_timeout = 200

1
  • While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value. Please read this how-to-answer for providing quality answer. Commented Jun 24, 2017 at 11:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.