Quantcast
Channel: WCF, ASMX and other Web Services
Viewing all articles
Browse latest Browse all 555

Is there a way to strip off the namespace of my object properties for XML serialization

$
0
0

I hope i am explaining this correctly.

I am getting the error below, and thinking it has something to do with the namespace (see highlighted)

Is there a way to strip off the namespace when I build up my object to serialize to XML.

So when i build up the object (see below)

I thing the issue is the namespace that is showing up before the "HCIM_IN_GetDemographics"

Here is my debugging code on when i serialize:

System.Diagnostics.Debug.WriteLine(Serialize(batchRequest));

public static string Serialize(Object obj)
        {
            try
            {

                using (var sw = new StringWriter())
                {
                    string objType = obj.GetType().Name.ToString();

                    var serializer = new XmlSerializer(obj.GetType(), new Type[] { obj.GetType() });
                    XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();
                    namespaces.Add("hl7", "urn:hl7-org:v3");

                    serializer.Serialize(sw, obj, namespaces);
                    return sw.GetStringBuilder().ToString();
                }

            }
            catch (Exception e) { return e.Message; }
        }

I guess my question is, (assuming the Namespace is the issue)  Is there anyway to remove that namespace, so that when i serialize the object, it won't give me that error?

Any ideas are greatly appreciated.

Thanks in advance !


Viewing all articles
Browse latest Browse all 555

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>