我目前正在与SOAP服务集成,该服务定义了两个不同的服务。
WSDL的相关部分是:
<wsdl:service name="Config"> <wsdl:port name="BasicHttpBinding_IConfiguration" binding="tns:BasicHttpBinding_IConfiguration"> <soap:address location="http://nonsecure.example.com/Configuration.svc"/> </wsdl:port> <wsdl:port name="BasicHttpsBinding_IConfiguration" binding="tns:BasicHttpsBinding_IConfiguration"> <soap:address location="https://secure.example.com/Configuration.svc"/> </wsdl:port> </wsdl:service>
通过研究,我发现可以使用__setLocation()方法来控制
$client->__setLocation('https://secure.example.com/Configuration.svc');但是,我不应该直接写死它,应该根据端口优先选择https。
于是封装一个方法来优先获取https端口
function getLocationForPort($wsdl, $portName)
{
$file = file_get_contents($wsdl);
$xml = new SimpleXmlElement($file);
$query = "wsdl:service/wsdl:port[@name='$portName']/soap:address";
$address = $xml->xpath($query);
if (!empty($address))
{
$location = (string)$address[0]['location'];
return $location;
}
return false;
}用法很简单:
$client = new SoapClient($wsdl);
$sslLocation = getLocationForPort($wsdl, 'BasicHttpsBinding_IConfiguration');
if ($sslLocation)
{
$client->__setLocation($location);
}
/** * 计算两点地理坐标之间的距离 * @param Decimal $longitude1 起点经度 * @param Decimal $lati...
应用场景:PHP模拟购买,商品数量大于0才能购买常见代码:<?php //连接数据库 $con=mysqli_connect("localhost","ihuohuo","927464cy","ihuohuo");...
001源码:/* * $xml_str是xml字符串 */ function xmltoarray($xml_str) { //禁止XML实体扩展攻击 libxml_disable_entity_loader(true); //拒绝包含...
(1).学习的目标:学会创建父子进程,并且能够区分当前进程是父还是子;了解父进程执行过程,子进程执行过程;能够用多进程执行任务(2).相关函数学习: (2.1)pcntl_fork()执行时: &nbs...
<?php /** * @throws Exception */ function curl() { throw new \Exception('err...
【一】.迭代器迭代是指反复执行一个过程,每执行一次叫做一次迭代。比如下面的代码就叫做迭代:1. <?php 2. $data = ['1', '2', &...