Search code examples
c#asp.netweb-serviceswsdlwebservice-client

Error consuming wsdl web service with c# The formatter threw an exception while trying to deserialize the message


I am trying to consume a wsdl web service (java) using C#. I added the service reference and implemented the webmethod call but it is returning following error: The formatter threw an exception while trying to deserialize the message:

There was an error while trying to deserialize parameter http://services.company.companyname.com.br:methodNameResponse. The InnerException message was 'Error in line 1 position 456. 'EndElement' 'methodNameReturn' from namespace 'http://services.company.companyname.com.br' is not expected. Expecting element 'idSomething'.'. Please see InnerException for more details.

I already tried lot of things, like limits of sizes, add ip on host file, etc, but no success. Does anyone have an idea?

The code is:

var ws = new webService(); //invoked using the service reference
var return = ws.methodName("x", "CAY", "5454545", "XXXX", "xxx", "09/07", "A", 1,
                                               "23/04/2013", "23/04/2013", "15:00", "17:00");

The ws.methodName returns the error.

I already tried with request and response objects and got the same error.

I tested yet using web reference. I got a way it does not return me error, but I needed alter the reference file, commenting the following line, above the invoked method:

[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://dto.services.company.trielo.com.br")]

I'm posting the wsdl: http://177.140.208.200:8998/mdc4web/services/VisitantesSASweb?wsdl


Solution

  • I found two possibles problems between the proxy class generated by Visual Studio and service WSDL

    Looking the proxy generated file:

    First mistake is the namespace parameter at XmlTypeAttribute attribute in RetVisSRV class

    [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://dto.services.mdc4web.trielo.com.br")]
    

    you need to remove the "dto."

    [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://services.mdc4web.trielo.com.br")]
    

    The second point is the elementName parameter at XmlArrayItemAttribute of "lst" array declaration.

    [System.Xml.Serialization.XmlArrayItemAttribute("item", Namespace="http://services.mdc4web.trielo.com.br", IsNullable=false)]
    

    correct to "lst"

    [System.Xml.Serialization.XmlArrayItemAttribute("lst", Namespace="http://services.mdc4web.trielo.com.br", IsNullable=false)]
    

    After these changes should work fine.

    This namespaces problems are a known issue between AXIS and .NET clients, but I don't why is not yet solved

    See https://issues.apache.org/jira/browse/AXIS-2449

    Hope this helps