简体   繁体   English

如何在php中使用WSDL定义备用soap Web服务

[英]how to define alternate soap web service using WSDL in php

I have a soap server and a soap client on different servers. 我在不同的服务器上有一个肥皂服务器和一个肥皂客户端。 My problem is that my internet link for soap server is flapping very frequently therefore I am deciding to take another internet link for soap server so if primary link down I will move to back up link and vice versa. 我的问题是,我的肥皂服务器的互联网链接经常抖动,因此,我决定使用另一个肥皂服务器的互联网链接,因此,如果主链接断开,我将转向备份链接,反之亦然。 But how I can tackle this condition in my php soap client that when IP change so address of wsdl change automatically instead of changing manually each time. 但是我如何在我的php soap客户端中解决这种情况,即当IP更改时,wsdl的地址会自动更改,而不是每次都手动更改。 for example I have below WSDL links for two differnet IPS 例如,我在下面的WSDL链接中有两个differnet IPS

<?php
$url1 = "http://x.x.x.x/api?wsdl"; //primary link IP
$url2 = "http://a.a.a.a/api?wsdl"; //back up link IP

$client = new SoapClient($url1 or $url2,array("trace"=>1,"exceptions"=>0));   //Now defining a client with url which is currently active.

?>

How to define th client after checking the active internet link at soap server? 检查肥皂服务器上的活动Internet链接后如何定义客户端?

For a simple solution, you could just check if the primary wsdl can be accessed, and if it can't, use the secondary wsdl: 对于一个简单的解决方案,您可以只检查是否可以访问主要的wsdl,如果不能,则使用辅助的wsdl:

$url1 = "http://x.x.x.x/api?wsdl";
$url2 = "http://a.a.a.a/api?wsdl";

try {
  $headers = @get_headers($url1);
  if(!empty($headers)) {
    $wsdl = $url1;
  } else {
    $wsdl = $url2;
  }
  $client = new SoapClient($wsdl, array("trace"=>1,"exceptions"=>0));
} catch (Exception $e) {

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM