Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

DeserializationFailed error

Help
2008-09-10
2013-06-06
  • Hi, i'm new at using nusoap but I have managed to get it working with simple testfunction on a webservice that I need to use.
    The simple function was a HelloWorld feuntion but now I need to use one called GetCustomer. I haven't created the webservice it is owned by a compay. However they have never had anyone use it with PHP so they can't help much.

    I have used soapUI to try it out and it works well, so it is my code that is wrong. But I can't find what or where...

    This is the error I get:
    ----------------------------------------------
    Fault
    Array
    (
        [faultcode] => a:DeserializationFailed
        [faultstring] => Array
            (
                [!xml:lang] => nb-NO
                [!] => The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:user. The InnerException message was 'Error in line 1 position 461. 'EndElement' 'user' from namespace 'http://tempuri.org/' is not expected. Expecting element 'Username'.'.  Please see InnerException for more details.
            )

        [detail] => Array
            (
                [ExceptionDetail] => Array
                    (
                        [HelpLink] =>
                        [InnerException] => Array
                            (
                                [HelpLink] =>
                                [InnerException] =>
                                [Message] => Error in line 1 position 461. 'EndElement' 'user' from namespace 'http://tempuri.org/' is not expected. Expecting element 'Username'.
                                [StackTrace] =>    at System.Runtime.Serialization.XmlObjectSerializerReadContext.ThrowRequiredMemberMissingException(XmlReaderDelegator xmlReader, Int32 memberIndex, Int32 requiredIndex, XmlDictionaryString[] memberNames)
       at ReadAFSUserFromXml(XmlReaderDelegator , XmlObjectSerializerReadContext , XmlDictionaryString[] , XmlDictionaryString[] )
       at System.Runtime.Serialization.ClassDataContract.ReadXmlValue(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context)
       at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator reader, String name, String ns, DataContract& dataContract)
       at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator xmlReader, Type declaredType, DataContract dataContract, String name, String ns)
       at System.Runtime.Serialization.DataContractSerializer.InternalReadObject(XmlReaderDelegator xmlReader, Boolean verifyObjectName)
       at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName)
       at System.Runtime.Serialization.DataContractSerializer.ReadObject(XmlDictionaryReader reader, Boolean verifyObjectName)
       at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeParameterPart(XmlDictionaryReader reader, PartInfo part, Boolean isRequest)
                                [Type] => System.Runtime.Serialization.SerializationException
                            )

                        [Message] => The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:user. The InnerException message was 'Error in line 1 position 461. 'EndElement' 'user' from namespace 'http://tempuri.org/' is not expected. Expecting element 'Username'.'.  Please see InnerException for more details.
                        [StackTrace] =>    at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeParameterPart(XmlDictionaryReader reader, PartInfo part, Boolean isRequest)
       at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeParameter(XmlDictionaryReader reader, PartInfo part, Boolean isRequest)
       at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeParameters(XmlDictionaryReader reader, PartInfo[] parts, Object[] parameters, Boolean isRequest)
       at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeBody(XmlDictionaryReader reader, MessageVersion version, String action, MessageDescription messageDescription, Object[] parameters, Boolean isRequest)
       at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeBodyContents(Message message, Object[] parameters, Boolean isRequest)
       at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeRequest(Message message, Object[] parameters)
       at System.ServiceModel.Dispatcher.DispatchOperationRuntime.DeserializeInputs(MessageRpc& rpc)
       at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
       at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
       at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc)
       at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc)
       at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc)
       at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc)
       at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
                        [Type] => System.ServiceModel.Dispatcher.NetDispatcherFaultException
                    )

            )

    )

    Request
    POST /AFSServices/AFSService.svc/basicHttpBinding HTTP/1.0
    Host: testhorizon.gothiagroup.com
    User-Agent: NuSOAP/0.7.3 (1.114)
    Content-Type: text/xml; charset=UTF-8
    SOAPAction: "http://tempuri.org/IAFSService/GetCustomer"
    Content-Length: 635

    <?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns8867="http://tempuri.org"><SOAP-ENV:Body><GetCustomer xmlns="http://tempuri.org/"><user><Username>aaaaa</Username><Password>xxxxxx</Password><ClientID>1111</ClientID></user><customerNo>1</customerNo><orgno/><firstname/><lastname/><ssn/><bornDate/><address/><postalCode/><postalPlace/><countryCode/></GetCustomer></SOAP-ENV:Body></SOAP-ENV:Envelope>
    ----------------------------------------------

    And this is the code I use to produce it:

    ----------------------------------------------
    <HTML>
    <HEAD>
    <TITLE>AFSWS Test</TITLE>
    </HEAD>
    <BODY>
    <?

    echo '<h2>PHP koppling till AFSWS WSDL GetCustomer funktion</h2><br>';

    /*
    * Ange sökvägen till nusoap biblioteket
    */
    require_once('../lib/nusoap.php');

    /*
    * Ange sökvägen till webservicen
    */
    $wsdl='http://testhorizon.gothiagroup.com/AFSServices/AFSService.svc?wsdl';

    /*
    * Skapa en klient för den angiva webservicen
    */
    $client = new nusoap_client($wsdl, 'wsdl');

    /*
    * Kolla om fel uppstod, i så fall skriv ut dessa
    */
    $err = $client->getError();
    if ($err) {
        echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
    }

    /*
    * Här kommer själva funktionsanropen till webservicen.
    * Parametrarna för ett funktionsanrop anges i en array son har samma form som den variabel/objekt som ska skickas in.
    * Arrayen kan vara nästlad med många arrayer som bygger upp ett objects struktur.
    * Variablerna och/eller objektet som retuneras sparas alla i $result_funtionsnamn i formen av en array.
    */

    // GetCustomer funktionsanrop
    $user = array(
          'Username' => 'aaaaa',
          'Password' => 'xxxxxxx',
          'ClientID' => 1111
    );
    $customerNo = array(
                'customerNo' => 1
    );
    $param = array(
           'user' => $user,
           'customerNo' => 1
    );
    $result_GetCustomer = $client->call('GetCustomer', $param);

    // Check for a fault
    if ($client->fault) {
        echo '<h2>Fault</h2><pre>';
        print_r($result_GetCustomer);
        echo '</pre>';
    } else {
        // Check for errors
        $err = $client->getError();
        if ($err) {
            // Display the error
            echo '<h2>Error</h2><pre>' . $err . '</pre>';
        } else {
            // Display the result
            echo '<h2>Result</h2><pre>';
            print_r($result_GetCustomer);
            echo '</pre>';
        }
    }
    echo '<h2>Request</h2><pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
    //echo '<h2>Response</h2><pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
    //echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';
    ?>
    </BODY>
    </HTML>
    ----------------------------------------------

    What can be wrong?