Sirius
Sirius

Reputation: 404

PHP SOAP - Element or attribute do not match QName production: QName::=(NCName':')?NCName

I saw here some people having the same problem, but nothing I've found help me, my case seem to be a more specific.

My PHP Code:

        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>';
}

When it is called, I got the error:

[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
                )
        )

And the XML I got from _getLastRequest() is:

<?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>

The XML that I know it works because was tested in 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>

I simplified the XML because it is larger (all string or int type), but all complex part are there.

I have no idea why the XML from PHP are so different from the SOAPUi, but certainly something I did wrong.

Can some one give a clue about what can I do or how to fix PHP XML to be equal SOAPUi XML?

Upvotes: 1

Views: 578

Answers (1)

Sirius
Sirius

Reputation: 404

The problem was that my server need to have WS-Security in a correct way, and for some reason, it got lost and gave that inaccurate error information.

I found the way to do it right in:

Connecting to WS-Security protected Web Service with PHP

The best answer is not the accepted one, but this one.

Upvotes: 1

Related Questions