dongruoqiong9017 2012-06-22 22:51
浏览 205
已采纳

soap error致命错误:未捕获的SoapFault异常:[HTTP]无法连接到主机

I encounter this error when sending a SOAP request with the PHP SoapClient:

Fatal error: Uncaught SoapFault exception: [HTTP] Could not connect to host in /var/www/phpwebservice/soap-client.php:6
Stack trace:
#0 [internal function]: SoapClient->__doRequest('__call('getCatalogEntry', Array)
#2 /var/www/phpwebservice/soap-client.php(6): SoapClient->getCatalogEntry('catalog1')
#3 {main} thrown in /var/www/phpwebservice/soap-client.php on line 6

the script works fine when moving the files directly under the /var/www/ meaning:

http://localhost/soap-client.php

but when I move it to a sub-folder called phpwebservice that error appears. It doesn't matter if the sub-folder is like this:

http://localhost/phpwebservice/soap-client.php

or if I made a VirtualHost for it:

http://phpwebservice/soap-client.php

the content of soap-client.php:

    $client     = new SoapClient("catalog.wsdl");
    $catalogId      = 'catalog1';
    $response       = $client->getCatalogEntry($catalogId);
    echo $response;

soap-server.php:

    function getCatalogEntry($catalogId){
    if($catalogId == 'catalog1')
            return  "<html>
                <head>
                    <title>catalog</title>
                </head
                <body>
                <p> </p>
                    <table border=1>
                    <tr>
                        <th>catalogid</th>
                        <th>journal</th>
                        <th>section</th>
                        <th>edition</th>
                        <th>title</th>
                        <th>author</th>
                    </tr>
                    <tr>
                        <td>catalog1</td>
                        <td>ibm developerworks</td>
                        <td>xml</td>
                        <td>october 2005</td>
                        <td>jaxp validation</td>
                        <td>brett mclaughlin</td>
                    </tr>
                    </table>
                </body>
            </html>";
elseif($catalogId == 'catalog2')
    return  "<html>
                <head>
                    <title>catalog</title>
                </head>
                <body>
                    <p> </p>
                    <table border=1>
                        <tr>
                            <th>catalogid</th>
                            <th>journal</th>
                            <th>section</th>
                            <th>edition</th>
                            <th>title</th>
                            <th>author</th>
                        </tr>
                        <tr>
                            <td>catalog1</td>
                            <td>ibm developerworks</td>
                            <td>xml</td>
                            <td>july 2006</td>
                            <td>the java xpath api</td>
                            <td>elliotte harold</td>
                        </tr>
                    </table>
                </body>
            </html>";
    }
    ini_set("soap.wsdl_cache_enabled", "0");
    $server = new soapserver("catalog.wsdl");
    $server->addfunction("getCatalogEntry");
    $server->handle();

catalog.wsdl:

   <?xml version ='1.0' encoding ='UTF-8' ?>
   <definitions name='Catalog'
   targetnamespace='http://phpwebservice/catalog'
   xmlns:tns='http://phpwebservice/catalog'
   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 name='getCatalogRequest'>
    <part name='catalogId' type='xsd:string'/>
   </message>
   <message name='getCatalogResponse'>
    <part name='Result' type='xsd:string'/>
   </message>
   <portType name='CatalogPortType'>
    <operation name='getCatalogEntry'>
                <input message='tns:getCatalogRequest'/>
        <output message='tns:getCatalogResponse'/>
    </operation>
   </portType>
   <binding name='CatalogBinding' type='tns:CatalogPortType'>
    <soap:binding style='rpc' transport='http://schemas.xmlsoap.org/soap/http'/>
    <operation name='getCatalogEntry'>
    <soap:operation soapAction='urn:phpwebservice-catalog#getCatalogEntry'/>
        <input>
            <soap:body use='encoded' namespace='urn:phpwebservice-catalog' encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
        </input>
        <output>
                    <soap:body use='encoded' namespace='urn:phpwebservice-catalog' encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
        </output>
    </operation>
   </binding>
   <service name='CatalogService'>
    <port name='CatalogPort' binding='CatalogBinding'>
        <soap:address location='http://phpwebservice/soap-server.php'/>
   </port>
   </service>
   </definitions>

thanx.

  • 写回答

3条回答 默认 最新

  • dongweng6241 2012-06-25 19:42
    关注

    never mind i just remove the /catalog from every line that it's in from the wsdl file, everything works fine now thanx anyway.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料