我是Web和php的新手...
我正在尝试通过wsdl链接访问Web服务以获取ping请求。相应的服务器位于通过LAN访问的专用网络上,并且它是脱网的。我写了以下index.php:
<?php
require_once('api/checkserviceavailability.php');
$url = "http://ipAddress:port/###########?wsdl";
$action = "http://*action_Url*";
$respone = new RunProcess($url, $action);
echo "OutPut ".$respone->FirstCall();
?>
剩余的过程在api / checkserviceavailability.php目录中
<?php
error_reporting(E_ALL);
ini_set('display_errors',1);
class RunProcess{
private $url ="http://ipAddress:port/###########?wsdl";
private $action ="http://*action_Url*";
public function __construct($url, $action){
$this->url = $url;
$this->action = $action;
}
public function FirstCall(){
$soapEnvelopeXml = $this->CreateSoapEnvelope();
$WebRequest = $this->CreateWebRequest($this->url ,$this->action);
return $parser = simplexml_load_string($WebRequest);
}
public function CreateWebRequest($url, $action){
$url = $url;
$headers = array(
"Content-type: text/xml",
"Content-length: " . strlen($action),
"Connection: close",
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $action);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$data = curl_exec($ch);
return $data;
}
public function CreateSoapEnvelope(){
$string = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:bas="http://*action_Url*"><soapenv:Header/><soapenv:Body><bas:checkServiceAvailabilityRequest><requestID/><requestDate/><requestOrigin/><requestMsg>PING</requestMsg></bas:checkServiceAvailabilityRequest></soapenv:Body></soapenv:Envelope>';
$dom = new DOMDocument();
return $dom->loadXML($string);
}
}
我以前在C#中运行过代码,得到了肯定的答复。然后尝试将代码托管在htdocs中的xampp中,这意味着当我连接到LAN时,将从本地主机运行该代码。我不知道它是否没有通过或失败,因为它是LocalHost。如果是这样,我该怎么办或使用它来运行和测试计算机上的代码。