1

I'm trying to feed the xml a java web service spits out through xml deserialization, but seems the xml files I have are missing the namespaces. Here's the C# class generated from WSDL:

[XmlTypeAttribute(Namespace="http://mynamespace.com")]
public class Customer {

    [XmlElementAttribute(IsNullable=true)]
    public string customerNo {
        get; set;
    }

    [XmlElementAttribute(IsNullable=true)]
    public string customerType {
        get; set;
    }
}

See the namespace definition? The actual XML files miss the namespace declaration and look like this:

<?xml version="1.0"?>
<Customer>
    <customerNumber>1234</customerNumber>
    <customerType />
</CreditCard>

Xml deserializer deserializes the root object but all the properties are null. I managed to get it working by either removing the XmlTypeAttribute or adjusting the xml file by adding namespaces:

<xml version="1.0"?>
<Customer>
    <customerNumber xmlns="http://mynamespace.com">1234</creditCardNo>
    <customerType xsi:nil="true" xmlns="http://mynamespace.com" />
</Customer>

The problem is that the actual xml files are large and I don't want to do that manually and don't want to remove the attribute either. What's the easiest way to make it work? Regenerating the whole document with proper xmlns attributes and deserialize using that instead?

Hadi Eskandari
  • 25,575
  • 8
  • 51
  • 65
  • Is this an RPC-style web service? There can be "controversy" about the meaning of the parameters to such a service. Can you post an excerpt of the WSDL? In particular, the `message`, corresponding XML schema, `operation`, `binding`, etc. – John Saunders Jul 10 '12 at 00:59
  • This is an RPC webservice, what I'm trying to do is to play arbitrary xml snippets handed by customer as responses but unfortuantely the xml files are large and do not conform to the WSDL so I'm having this deserialization issue. – Hadi Eskandari Jul 10 '12 at 01:02
  • That class definition generates proper namespaces when I try. Even `xmlns:xsi` and `xmlns:xsd`. How are you calling the serializer? – Markus Jarderot Jul 10 '12 at 09:55
  • @MarkusJarderot I'm trying to deserialize the xml without "xmlns"s, serializing the class into xml of course works fine, but that's not what I'm trying to do. – Hadi Eskandari Jul 10 '12 at 23:02
  • The second answer to this question should help: [Serializing WITHOUT xmlns](http://stackoverflow.com/questions/3094471/serializing-without-xmlns) – Markus Jarderot Jul 11 '12 at 05:56
  • @MarkusJarderot That's exactly what I did to solve the issue today. Thanks. – Hadi Eskandari Jul 11 '12 at 05:59

0 Answers0