php soap 客户端,错误 wsdl 导致的错误?“未捕获的 SoapFault 异常:[HTTP] 无法连接到主机" [英] php soap client, error from bad wsdl? "Uncaught SoapFault exception: [HTTP] Could not connect to host"

查看:32
本文介绍了php soap 客户端,错误 wsdl 导致的错误?“未捕获的 SoapFault 异常:[HTTP] 无法连接到主机"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 SOAP 的新手,所以我制作了一个小测试脚本来连接到我客户的服务器.他们在那里有一个 GetMessage 命令,不需要输入或身份验证,只是为了测试连接性:

I'm mostly new to SOAP, so I made a little test script to connect to my customer's server. They have a GetMessage command in there, that requires no input or authentication and is just intended to test connectivity:

<?php
ini_set('soap.wsdl_cache_enabled',0);
ini_set('soap.wsdl_cache_ttl',0);

$url        = "https://test.mycustomer.com/api/TestService.svc?wsdl";
$client     = new SoapClient($url, array("trace" => 1, "exception" => 0));

$result = $client->GetMessage(NULL);

echo "<pre>".print_r($result, true)."</pre>";
if($result->GetMessageResult->Status == "Success")
{
    echo "Item deleted!";
}
?>

如果我在命令行中运行它,我会得到:

If I run this in the command line I get:

Fatal error: Uncaught SoapFault exception: [HTTP] Could not connect to host in /var/www/my.stage.com/htdocs/common/soaptest.php:8
Stack trace:
#0 [internal function]: SoapClient->__doRequest('<?xml version="...', 'http://459265-d...', 'http://tempuri....', 1, 0)
#1 [internal function]: SoapClient->__call('GetMessage', Array)
#2 /var/www/my.stage.com/htdocs/common/soaptest.php(8): SoapClient->GetMessage(NULL)
#3 {main}
  thrown in /var/www/my.stage.com/htdocs/common/soaptest.php on line 8

从浏览器中我得到:

PHP Notice: 'SoapClient::__doRequest() [soapclient.--dorequest]: php_network_getaddresses: getaddrinfo failed: Name or service not known' 

在此服务的 WSDL 中,字符串459265"出现在此处:

In their WSDL for this service, the string "459265" appears here:

<wsdl:service name="TestService">
<wsdl:port name="BasicHttpBinding_ITestService" binding="tns:BasicHttpBinding_ITestService">
<soap:address location="http://459265-dev1/api/TestService.svc"/>
</wsdl:port>
<wsdl:port name="BasicHttpsBinding_ITestService" binding="tns:BasicHttpsBinding_ITestService">
<soap:address location="https://test.mycustomer.com/api/TestService.svc"/>
</wsdl:port>
</wsdl:service>

所以我的问题是,这是正确的吗?WSDL 是否应该有一个我无法从我的盒子访问的本地 url?

So my question is, is that correct? Should the WSDL have a local url like that, that I can't get to from my box?

更多信息,当我对 __getFunctions 和 __getTypes 执行 var_dump 时,我得到

A little more info, when I do a var_dump on __getFunctions and __getTypes, I get

array(2) {
  [0]=>
  string(53) "GetMessageResponse GetMessage(GetMessage $parameters)"
  [1]=>
  string(53) "GetMessageResponse GetMessage(GetMessage $parameters)"
}
array(5) {
  [0]=>
  string(21) "struct GetMessage {
}"
  [1]=>
  string(55) "struct GetMessageResponse {
 string GetMessageResult;
}"
  [2]=>
  string(8) "int char"
  [3]=>
  string(17) "duration duration"
  [4]=>
  string(11) "string guid"
}

推荐答案

您想要做的是将您的代码包装在 try{}, catch{} 块中.例如,

What you want to do is wrap your code in a try{}, catch{} block. For example,

<?php
    try {
        ini_set('soap.wsdl_cache_enabled',0);
        ini_set('soap.wsdl_cache_ttl',0);

        $url = "https://test.mycustomer.com/api/TestService.asmx?wsdl";
        $client = new SoapClient($url, array("trace" => 1, "exception" => 0));

        $result = $client->GetMessage(NULL);

        echo "<pre>".print_r($result, true)."</pre>";
        if($result->GetMessageResult->Status == "Success")
        {
            echo "Item deleted!";
        }
    }
    catch (SoapFault $exception) {
        echo $exception->getMessage();
    }
?>

正如错误所说,Fatal error: Uncaught SoapFault exception: [HTTP] could not connect to host in ....,所以无论如何你都需要捕获异常.希望这会有所帮助.

As the error says, Fatal error: Uncaught SoapFault exception: [HTTP] Could not connect to host in ...., so you need to catch the exception in any case. Hope this helps.

这篇关于php soap 客户端,错误 wsdl 导致的错误?“未捕获的 SoapFault 异常:[HTTP] 无法连接到主机"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆