【问题标题】:unexpected 'targetNamespace' Cannot import XSD意外的“targetNamespace”无法导入 XSD
【发布时间】:2012-10-11 19:06:57
【问题描述】:

我有一个定义如下的 WSDL。不确定定义有什么问题,但每次我尝试导入时,我都会收到错误

    <definitions targetNamespace="myservices" 
      xmlns:nslt2="myxsdspace"
      xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" 
      xmlns="http://schemas.xmlsoap.org/wsdl/" 
      xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
      xmlns:tns="urn:myservices" 
      xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
      xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
      xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/">
  <types>
    <schema elementFormDefault="unqualified" 
    targetNamespace="myservices" xmlns="http://www.w3.org/2001/XMLSchema"/>
      <xsd:schema>
        <xsd:import namespace="myxsdspace" schemaLocation="ApplicaitonForm_Latest.xsd"/>
      </xsd:schema>
  </types>
  <message name="processRequest">

... ... ...

我收到以下错误,但无法找到解决方案。

SOAP-ERROR: Parsing Schema: can't import schema from 'myxsd.xsd', unexpected 'targetNamespace'='myxsdspace

非常感谢您的帮助

【问题讨论】:

标签: php namespaces wsdl


【解决方案1】:

给有同样烦恼的人的答案,

这通常与属性不匹配有关:在导入的 xsd 文件中,&lt;import&gt; 标记中的namespaceschema 标记中的targetNamespace

引发unexpected 'targetNamespace' 错误的不匹配属性示例:

文件 wsdl.xml

<xs:import namespace="http://www.example.fr/modules/payment/schema/qwerty"
                   schemaLocation="location.xsd"/>

文件位置.xsd

<xs:schema targetNamespace="http://www.example.fr/modules/payment/schema/azerty" ... >

因此,只需更正其中一个属性,错误就会消失:

文件 wsdl.xml

<xs:import namespace="http://www.example.fr/modules/payment/schema/qwerty"
                   schemaLocation="location.xsd"/>

文件位置.xsd

<xs:schema targetNamespace="http://www.example.fr/modules/payment/schema/qwerty" ... >

【讨论】:

    【解决方案2】:

    您使用的是什么版本的 PHP?您可以发布连接到 SOAP 的代码吗? PHP-SOAP 接口仍然非常挑剔,您可能需要对您的 WSDL 或 PHP 进行一些修改才能使其满意。对于初学者,请尝试设置肥皂选项以强制使用肥皂版本。另外,请查看是否可以通过对错误运行var_dump 来获取更多详细信息,如下所示。

    $soapServer = 'http://yoursoap.com/wsdl';
    $soapOptions = array(
            'soap_version'    => SOAP_1_1,
            'exceptions'      => true,
            'trace'           => 1,
            'wsdl_local_copy' => true,
            'keep_alive'      => true,
            'features'        => SOAP_SINGLE_ELEMENT_ARRAYS
            );
    
    try
    {
        $soapClient = new SoapClient($soapServer, $soapOptions);
    }
    catch (Exception $e)
    {
        $message = "<h2>Connection Error!</h2></b>";
        var_dump($e);
    }
    

    【讨论】:

      【解决方案3】:

      您提交的 WSDL 不完整。根元素没有关闭,还有其他不完整的元素。您将无法解析语法不规范的 WSDL

      【讨论】:

        猜你喜欢
        • 2015-10-14
        • 1970-01-01
        • 1970-01-01
        • 2020-03-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-06-18
        • 2019-11-05
        相关资源
        最近更新 更多