问题描述
我正在尝试使用PHP& SOAP,但到目前为止,我所得到的是:
I'm trying to run a web service using PHP & SOAP, but all I'm getting so far is this:
我尝试将localhost更改为127.0.0.1,但这没什么区别. login实际上是一个wsdl文件,但是如果我将login.wsdl放入SOAPClient构造函数中,它会显示看起来好像没有XML文档".
I've tried changing localhost to 127.0.0.1, but that makes no difference. login is actually a wsdl file, but if I put login.wsdl in the SOAPClient constructor, it says "'looks like we got no XML document'" instead.
这是我的SOAP客户端代码(register_client.php):
Here is my code for the SOAP Client (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文件:
And here is the login.wsdl file:
<?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的代码:
And I'm not sure if this is involved, so I'm providing the code for the SOAP Server 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,以及我能做什么,我将非常感激.进行纠正.
I'm sorry if I'm giving unnecessary information, but I'm a complete novice at this - and I'd really appreciate it if someone could point out why exactly this SOAP Fault is being generated, and what I can do to rectify it.
我正在使用WAMP Server 2.2版,mySQL 5.5.24和PHP 5.3.13
I am using WAMP Server version 2.2, with mySQL 5.5.24 and PHP 5.3.13
推荐答案
迁移到PHP 5.6.5之后,soap 1.2不再起作用.因此,我通过添加可选的SSL参数解决了该问题.
After migrating to PHP 5.6.5, the soap 1.2 did not work anymore. So I solved the problem by adding optional SSL parameters.
我的错误:
解决方法:
// options for ssl in php 5.6.5
$opts = array(
'ssl' => array(
'ciphers' => 'RC4-SHA',
'verify_peer' => false,
'verify_peer_name' => false
)
);
// SOAP 1.2 client
$params = array(
'encoding' => 'UTF-8',
'verifypeer' => false,
'verifyhost' => false,
'soap_version' => SOAP_1_2,
'trace' => 1,
'exceptions' => 1,
'connection_timeout' => 180,
'stream_context' => stream_context_create($opts)
);
$wsdlUrl = $url . '?WSDL';
$oSoapClient = new SoapClient($wsdlUrl, $params);
这篇关于SOAP PHP错误解析WSDL:无法加载外部实体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!