0

I have already visited this post but it is not helpful as I do not have control over serialization.

Background: I have a WSDL document which I have added as a web reference and got a reference.cs class. I am calling a service from .Net application but it is throwing an error while deserializing. Following are my XML files one which works fine and other which is giving me an error.

Works fine:

<soapenv:Envelope
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:mas="http://orgname.com/compxref/Sometype">
    <soapenv:Header/>
    <soapenv:Body>
        <mas:SomeInputType> 
    ...............

Throwing Error:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope
    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body>
        <SomeInputType
            xmlns="http://orgname.com/compxref/Sometype">
    .........................

My serialization class looks like below:

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.7.2612.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]    [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://orgname.com/compxref/Sometype")]

public partial class SomeInputType
{
    ...All the properties
}

Question: I want to change this XML to look like the one which is working fine. But here, I do not have control on serialization or deserialization. All I can do is to decorate Class and properties using data attributes.

Naresh Ravlani
  • 1,600
  • 13
  • 28
  • 1
    What error is it throwing? Additional namespace alias declarations *should* be irrelevant, and the final namespace of `SomeInputType` should be the same either way (although the inheritance of child elements may behave differently, but you haven't shown them) – Marc Gravell May 10 '18 at 13:48
  • @MarcGravell: Sorry I do not have the exact error message but it is something like "Error parsing XML: mismatched tag." or "Error parsing XML: mismatched element." The only difference in both the XML are in namespaces, apart from it, they are identical hence I I am assuming these namespaces are creating a problem somewhere. – Naresh Ravlani May 10 '18 at 13:56
  • the exact error message would be useful, because the two `SomeInputType` elements shown *are actually identical* - even if they are using different ways of expressing the namespace. My suspicion is that something *under* `SomeInputType` is in a different namespace, probably because of the different inheritance rules between alias-prefix vs `xmlns="..."`. Likewise, the `soapenv:Envelope` and `soap:Envelope` are actually identical – Marc Gravell May 10 '18 at 13:58
  • Ok, I will ask for the exact error message and will update the question once I have it. Meanwhile, if you know any way to stop the addition of these namespaces in XML serialization? – Naresh Ravlani May 10 '18 at 13:59
  • 1
    if you don't control the serialization, you can't control the aliases, but: I don't think that's the problem - they are at worst redundant; unnecessary aliases won't impact any compliant parser – Marc Gravell May 10 '18 at 14:41

0 Answers0