我正在尝试使用XML输出"Hello World",但我在php页面中得到以下异常:
Fatal error: Uncaught SoapFault exception: [HTTP] error getting HTTP headers in C:'wamp'www'Web_Service'SampleXML'index.php:4 Stack trace:
#0[内部函数]:SoapClient->_doRequest('#1[内部函数]:SoapClient->_call('getHelloWorld', Array)
#2 C:'wamp'www'Web_Service'SampleXML'index.php(4): SoapClient->getHelloWorld()
#3 {main}抛出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();
?>
我在代码中错过了什么吗?
尝试设置这一行,
ini_set("default_socket_timeout", 200);
或者放在php.ini
中 default_socket_timeout = 200
我想已经太晚了,但是我也有同样的问题。我尝试套接字超时,但它不工作。我的问题是,客户端和服务器在同一个物理服务器。由于客户端代码在同一物理服务器上工作,我得到了这个错误,但是,将相同的客户端代码移动到我的本地主机,请求服务器,(客户端和服务器在两台不同的机器上执行)所有工作正常。
也许这可以帮助别人!
我在密集的SOAP调用中遇到了这个问题,解决方案是在apache的httpd.conf中关闭KeepAlive。
我只是想报告这个错误是触发当你试图连接到一个服务器,这个服务器回复无效的数据或根本不回复。
增加超时时间可能会有帮助,但只有在服务器需要很长时间才能回复的上下文中,如前所述,您可以在php.ini
中增加值 default_socket_timeout = 200