PHP SOAP - 元素或属性与QName生成不匹配:QName :: =(NCName':')?NCName

时间:2017-03-10 16:47:03

标签: php xml soap xsd

我在这里看到有些人遇到同样的问题,但我找不到任何帮助,我的情况似乎更具体。

我的PHP代码:

        error_reporting( E_ALL );
        ini_set( 'display_errors', 1 );

        ini_set( 'soap.wsdl_cache_enabled',0 );
        ini_set( 'soap.wsdl_cache_ttl',0 );

        if( !class_exists('SoapClient') )
                die( "You haven't installed the PHP-Soap module." );

        $auth = array( 'Username' => 'MyUser', 'Password' => 'MyPassord' );

        $client = new SoapClient("Soap/MyWSDLFile.wsdl",
                array(
                        'trace' => 1,
                        'exception' => 0,
                )
        );

        $header = new SoapHeader( 'Soap/MyWSDLFile.wsdl',
                '"http://10.10.10.10/app/function"',
                $auth,
                false);

        $client->__setSoapHeaders( $header );


        $function = 'MY_FUNCTION';

        $dateNow = date('Y-m-d H:i:s');

        $params = array();
        $params[] = new SoapVar( '1', XSD_INT, null, null, 'Id' );
        $params[] = new SoapVar( 'My Name', XSD_STRING, null, null, 'Name' );
        $params[] = new SoapVar( 'my@email', XSD_STRING, null, null, 'Email' );

        $fill = array();
        $fill[] = new SoapVar( 'Couple Name', XSD_STRING, null, null, 'Couple' );
        $fill[] = new SoapVar( 'Child Name', XSD_STRING, null, null, 'Child' );

        $params[] = new SoapVar( $fill, SOAP_ENC_OBJECT, null, null, 'family' );

        $out = new SoapVar( $params, SOAP_ENC_OBJECT) ;
        $result = $client->RX_UPLOAD_CONVITE_EXPOSITOR( $out );
    var_dump( $result );
} catch ( SoapFault $e ) {
        echo $client->__getLastRequest() . "<br><br>";
        echo '<pre>'; print_r($e); echo '</pre>';
}

当它被调用时,我收到错误:

[previous:Exception:private] => 
    [faultstring] => PeopleSoftServiceListeningConnector:HTTPRequest : SAXException occured while parsing the SOAP Document. SAXExceptionMessage : Element or attribute do not match QName production: QName::=(NCName':')?NCName. 
    [faultcode] => SOAP-ENV:Server
    [detail] => stdClass Object
        (
            [IBResponse] => stdClass Object
                (
                    [DefaultTitle] => Integration Broker Response
                    [StatusCode] => 20
                    [MessageID] => 10201
                    [DefaultMessage] => Integration Gateway failed while processing the message
                )
        )

我从_getLastRequest()获得的XML是:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://10.10.10.10/app/function" xmlns:ns2="Soap/MyWSDLFile.wsdl">
        <SOAP-ENV:Header>
                <ns2:"http://10.10.10.10/app/function">
                        <item>
                                <key>Username</key>
                                <value>portal.user</value>
                        </item>
                        <item>
                                <key>Password</key>
                                <value>portal.user</value>
                        </item>
                </ns2:"http://10.10.10.10/app/function">
        </SOAP-ENV:Header>
        <SOAP-ENV:Body>
                <ns1:function>
                        <Id>1</Id>
                        <Name>My Name</Name>
                        <Email>my@email</Email>
                        <family>
                                <Couple>Couple Name</Couple>
                                <Child>Child Name</Child>
                        </family>
                </ns1:function>
        </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

我知道它运行的XML因为在SOAPUi中测试过:

<?xml version="1.0"?>
<xsd:schema elementFormDefault="qualified" targetNamespace="http://10.10.10.10/app/function" xmlns="http://10.10.10.10/app/function" 

xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <xsd:element name="FunctionRequest" type="FUNCTION_REQUEST_TYPE"/>
        <xsd:complexType name="FUNCTION_REQUEST_TYPE">
                <xsd:sequence>
                        <xsd:element name="Id" type="xsd:int"/>
                        <xsd:element name="Name" type="xsd:string"/>
                        <xsd:element name="Email" type="xsd:string"/>
                        <xsd:element name="Family" type="FAMILY_TYPE"/>
                </xsd:sequence>
        </xsd:complexType>
        <xsd:complexType name="FAMILY_TYPE">
                <xsd:sequence>
                        <xsd:element maxOccurs="10" name="Relatives" type="RELATIVE_TYPE"/>
                </xsd:sequence>
        </xsd:complexType>
        <xsd:complexType name="RELATIVE_TYPE">
                <xsd:sequence>
                        <xsd:element name="Couple" type="xsd:string"/>
                        <xsd:element name="Child" type="xsd:string"/>
                </xsd:sequence>
        </xsd:complexType>
</xsd:schema>

我简化了XML,因为它更大(所有字符串或int类型),但所有复杂的部分都在那里。

我不知道为什么PHP中的XML与SOAPUi如此不同,但肯定是我做错了。

有人能说清楚我能做些什么或如何修复PHP XML与SOAPUi XML相等?

1 个答案:

答案 0 :(得分:1)

问题是我的服务器需要以正确的方式使用WS-Security,并且由于某种原因,它丢失了并且提供了不准确的错误信息。

我找到了正确的方法:

Connecting to WS-Security protected Web Service with PHP

最好的答案不是被接受的答案,而是this one