使用soap时,无法连接到主机错误

时间:2016-12-15 08:39:12

标签: php web-services soap

我正在使用SOAP从Linux Centos 6服务器和web service客户端调用php。在本周,我无法通过soapCall方法连接到主机错误。我的代码如下所示,我几个月没有改变它,但最近它在大多数情况下都会出现这个错误。我在这里已经阅读了大部分相关问题的答案,但我的问题还没有解决。

$wsdl="http://x.x.x.x:x/gw/services/Service?wsdl";

//Set key as HTTP Header 
$aHTTP['http']['header'] =  "key:" .$key ."\r\n";

$context = stream_context_create($aHTTP);

try
{
  $client = new SoapClient($wsdl,array("soap_version" => SOAP_1_2,'trace' => 1,"stream_context" => $context));
}
catch(Exception $e)
{
        return "something";             
}
//I make $parametrs
try
{

 $res = $client->__soapCall("send",array($parametrs));
}
catch(Exception $e)
{
    print_r($e->getMessage()); //Most of the time it prints could not connect to host
}

我将SOAP从_1_1更改为_1_2但没有任何更改。

1 个答案:

答案 0 :(得分:0)

这就是我称之为SOAP webservice的方式,请注意服务?wsdl 应该 Service.wsdl

实施例

//Initialize values
$wsdl = "Service.wsdl";
$url = "http://x.x.x.x:x/gw/services/";
$username = "********"; //add username
$password = "********"; //add password


$client = new SoapClient("$url".$wsdl);
$params = array(
                "username"=>$username,
                "password"=>$password
                );
$response = $client->UserLogIn($params); //UserLogIn is the function name

var_dump($response);  // to see webservice response