.NET class is returning the empty namespace when i pass the XLangMessaage to method and returning the XmlDocument Object

Hi Friends, 

I have requirement to pass the XlangMessage to the .Net Method and do some complex validations and return the modified Xlang or XmlDoc message back to Biztalk. 

I have done following steps

1). I have Schema that has generated instance as shown below

<ns0:Airtime xmlns:ns0="http://PassXLangMesgToClasses.Airtime">
  <AirId>AirId_0</AirId>
  <AirName>AirName_0</AirName>
</ns0:Airtime>

2). i have created serialized class using following syntax 

XSD C:\Biztalk_Projects\PassXLangMesgToClasses\PassXLangMesgToClasses\Airtime.xsd /c /o:C:\Biztalk_Projects\PassXLangMesgToClasses\PassXLangMesgToClasses

3). Added serialized class to My Class Library Project 

4). I have added a class to the class library project and added following 2 methods to the class

public static XmlDocument UpdateMessage(XLANGMessage lMsg)
        {
            Airtime objAirtime = (Airtime)lMsg[0].RetrieveAs(typeof(Airtime));           
            try
            {
                //Update Book Object
                objAirtime.AirId = "U :" + objAirtime.AirId;
                objAirtime.AirName = "U :" + objAirtime.AirName;
            }
            catch (XLANGsException xlngEx)
            {
                throw xlngEx;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            //return book object
            return CreateXML(objAirtime);
        }

        public static XmlDocument CreateXML(Airtime airtime)
        {
            XmlDocument xmlDoc = new XmlDocument();

            XmlSerializer xmlSerializer = new XmlSerializer(airtime.GetType(), "");
            using (MemoryStream xmlStream = new MemoryStream())
            {
                xmlSerializer.Serialize(xmlStream, airtime);
                xmlStream.Position = 0;
                xmlDoc.Load(xmlStream);

                return xmlDoc;
            }
        }

5). Now i have added Orchestration to the project and it has receive shape and and message assignment shape and send shape. 

6). I have also created 2 messages of type msgAirtimeIn, msgAirtimeOut of same type Airtime, a variable of type XmLDoc 

now in Assignment shape i have following code that calls the external Library to update the Airtime Object. 

Variable_1= UpdateAirtimeProject.UpdateAirMessage.UpdateMessage(msgAirtimeIn);
msgAirtimeOut=Variable_1;

Sorry for long story. But my problem is when i return XMlDoc from .NET it is returning with empty xmlns="" tags to each element as shown below. I have tried on internet but there is no much help. Can anyone suggest me why am i getting that and how to get-rid of that. 

<?xml version="1.0"?>
<Airtime xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://PassXLangMesgToClasses.Airtime">
  <AirId xmlns="">U :AirId_0</AirId>
  <AirName xmlns="">U :AirName_0</AirName>
</Airtime>


April 26th, 2015 5:44pm

IMHO the only issue is that you're expecting that what you get from the message is a de-serialzed instance. That is WRONG. Your code should look like

public static XmlDocument UpdateMessage(XLANGMessage lMsg)
{
	XmlDocument xmlAirtime = (System.Xml.XmlDocument) lMsg[0].RetrieveAs(typeof(System.Xml.XmlDocument));
	StringReader msgReader = new StringReader(xmlAirtime.OuterXml);
	XmlSerializer xmlSerializer = new XmlSerializer(typeof(AirTime));
	Airtime objAirtime = (Airtime) xmlSerializer.Deserialize(msgReader);
	//Update Book Object
	objAirtime.AirId = "U :" + objAirtime.AirId;
	objAirtime.AirName = "U :" + objAirtime.AirName;
        //
	MemoryStream xmlStream = new MemoryStream();
        mlSerializer.Serialize(xmlStream, objAirtime);
        xmlStream.Seek(0L, Seek.Begin);
        xmlAirtime.Load(xmlStream);
	//
	return xmlAirTime;
}

You may choose to use XPATH to update the Data and not incur the additional load during serialization/de-serialization.

Regards

Free Windows Admin Tool Kit Click here and download it now
April 27th, 2015 1:47am

Hi venu,

I don't really understand the issue. Your request XML document is the following one:

<ns0:Airtime xmlns:ns0="http://PassXLangMesgToClasses.Airtime">
  <AirId>AirId_0</AirId>
  <AirName>AirName_0</AirName>
</ns0:Airtime>

The result of your helper class is the following one:

<Airtime xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://PassXLangMesgToClasses.Airtime">
  <AirId xmlns="">U :AirId_0</AirId>
  <AirName xmlns="">U :AirName_0</AirName>
</Airtime>

Both messages perfectly match your schema. If you want to qualify only the root node of a document, you have two options:
 - Define a prefix for the namespace and use this prefix in the root node. (You request document).
 - Define a default namespace for the document and set an empty namespace for the child nodes (The document generated by your helper).

Regards

April 27th, 2015 3:23am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics