我試圖運行使用PHP & SOAP Web服務,但所有我得到到目前爲止是這樣的:SOAP PHP故障解析WSDL:無法加載外部實體?
(SoapFault)[2] message which states: 'SOAP-ERROR: Parsing WSDL: Couldn't load from ' http://localhost/MyRegistration/login.xml ' : failed to load external entity " http://localhost/MyRegistration/login.xml "
我試圖改變本地主機爲127.0.0.1,但沒什麼區別。登錄實際上是一個wsdl文件,但如果我將login.wsdl放在SOAPClient構造函數中,它會顯示「'看起來像我們沒有XML文檔'」。
這裏是我的SOAP客戶端代碼(register_client.php):
<?php
try
{
$sClient = new SoapClient('http://127.0.0.1/MyRegistration/login.wsdl');
$param1 = $_POST["regname"];
$param2 = $_POST["regpass1"];
$response = $sClient->loginVerify($param1, $param2);
var_dump($response);
}
catch(SoapFault $e)
{
var_dump($e);
}
?>
這裏是login.wsdl文件:
<?xml version="1.0"?>
<definitions name="LoginVal"
targetNamespace="urn:LoginVal"
xmlns:tns="urn:LoginVal"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<types>
<xsd:schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:Login">
<xsd:element name="getName" type="xsd:string" />
<xsd:element name="getPass" type="xsd:string" />
<xsd:element name="LoginResponse" type="xsd:string" />
</xsd:schema>
</types>
<message name="loginVerify">
<part name="username" type="tns:getName" />
<part name="password" type="tns:getPass" />
</message>
<message name="doLoginResponse">
<part name="return" type="tns:LoginResponse" />
</message>
<portType name="LoginPort">
<operation name="loginVerify">
<input message="tns:loginVerify" />
<output message="tns:doLoginResponse" />
</operation>
</portType>
<binding name="LoginBinding" type="tns:LoginPort">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
<operation name="loginVerify">
<soap:operation soapAction="urn:LoginAction" />
<input>
<soap:body use="encoded" namespace="urn:Login" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</input>
<output>
<soap:body use="encoded" namespace="urn:Login" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</output>
</operation>
</binding>
<service name="LoginService">
<port name="LoginPort" binding="tns:LoginBinding">
<soap:address location="http://localhost/MyRegistration/register.php" />
</port>
</service>
</definitions>
而且我不知道這是因爲我提供了SOAP服務器register.php的代碼:
<?php
if(!extension_loaded("soap"))
{
dl("php_soap.dll");
}
ini_set("soap.wsdl_cache_enabled", "0");
$server = new SoapServer("login.wsdl", array('uri'=>'http://127.0.0.1/MyRegistration'))
public function loginVerify($username, $password)
{
if($_POST["regname"] && $_POST["regemail"] && $_POST["regpass1"] && $_POST["regpass2"])
{
if($_POST["regpass1"] == $_POST["regpass2"])
{
$servername = "localhost";
$username = "root";
$password = "Hellfire";
$conn = mysql_connect($servername,$username,"Hellfire")or die(mysql_error());
mysql_select_db("soap",$conn);
$sql = "insert into users (name,email,password)values('$_POST[regname]','$_POST[regemail]','$_POST[regpass1]')";
$result = mysql_query($sql,$conn) or die(mysql_error());
return "You have registered sucessfully";
//print "<a href='index.php'>go to login page</a>";
}
else return "passwords dont match";
}
else return "invalid data";
}
$server->AddFunction("loginVerify");
$server->handle();
?>
對不起,如果我給不必要的信息但我在這方面是一個完全新手 - 如果有人能指出爲什麼會產生這個SOAP Fault,以及我能做些什麼來糾正它,我真的很感激它。
我使用WAMP Server版本2.2,使用MySQL 5.5.24和5.3.13 PHP
我想補充的答案,這是由OpenSSL的變化5.6.x http://php.net/manual/en/migration56.openssl.php –
而不是禁用SSL同行動機驗證,您應該嘗試解決導致驗證失敗的問題。例如,通過明確地將路徑設置爲包含必要的根證書來驗證的cafile文件。答案到了問題的核心,有時這可能是唯一可用的解決方案,所以+1。 – deceze
像添加「openssl.cafile = C:/path/to/sslCertificates/cacert.pem」到php.ini :-)(如curl.cainfo!) –