SOAP PHP 错误解析 WSDL:无法加载外部实体? [英] SOAP PHP fault parsing WSDL: failed to load external entity?

查看:29
本文介绍了SOAP PHP 错误解析 WSDL:无法加载外部实体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 PHP & 运行 Web 服务SOAP,但到目前为止我所得到的只是:

I'm trying to run a web service using PHP & SOAP, but all I'm getting so far is this:

(SoapFault)[2] 消息指出:SOAP-ERROR:解析 WSDL:无法从 ' 加载http://localhost/MyRegistration/login.xml' : 无法加载外部实体 "http://localhost/MyRegistration/login.xml"

(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"

我已经尝试将 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 错误以及我能做什么,我真的很感激做来纠正它.

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 服务器版本 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

推荐答案

安全问题:此答案禁用安全功能,不应在生产中使用!

Security issue: This answer disables security features and should not be used in production!

迁移到 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:无法加载外部实体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆