none
BAM API RRS feed

  • Question

  • Hi,

    BizTalk Server 2013

    I'm getting following error when I pass my XLANG messages to a method in the helper class and trying to create XML Document from it:

    Inner exception: "Cannot use XLANGMessage.RetrieveAs to convert message part part with type Payments.Schemas.Vendor_Payments_BAM to type System.Xml.XmlDocument."

    The error is coming at the following syntax in the helper class:

    XmlDocument XmlDocMsg = (XmlDocument)msg[0].RetrieveAs(typeof(XmlDocument));

    The error is coming only when there are multiple nodes under the root element. When there is only one segment, it works fine.

    The same is working fine in BizTalk Server 2006 (with framework 2.0)

    Any help will be greatly appreciated.

    Wednesday, November 12, 2014 9:50 PM

Answers

  • A valid xml should always have one root. For e.g.

    <Vendor_Payment>
    <Payment_Info>
    <Payment_Run_ID>10</Payment_Run_ID>
    </Payment_Info>
    <Payment_Info>
    <Payment_Run_ID>11</Payment_Run_ID>
    </Payment_Info>
    </Vendor_Payment>

    is valid XML, and 

    <Payment_Info>
    <Payment_Run_ID>10</Payment_Run_ID>
    </Payment_Info>
    <Payment_Info>
    <Payment_Run_ID>11</Payment_Run_ID>
    </Payment_Info>

    is invalid.

    If you are sure about which ID you need you can use index to select using [n], and if you need to iterate through, you will need to assign valid xml to the XmlDocument (may be change xpath to nevigate to parent which hax Max Occur =1.

    fyi: you can't send invalid xml to sendport using XmlTransmit like you can't assign invalid xml to XmlDocument


    Please mark it as Answer if this answers your question
    Thanks.
    Mo
    The contents I write here is my personal views, not the view of my employer and anyone else.



    • Edited by Mohan Raj Aryal Wednesday, November 12, 2014 11:49 PM
    • Marked as answer by Angie Xu Tuesday, November 18, 2014 1:42 AM
    Wednesday, November 12, 2014 11:48 PM

All replies

  • It seems like it is not passing the XML validation. Tried to send out the message from ODX using send port with XmlTransmit pipeline, getting following error:

    Inner exception: The result set for the XPath expression '/*[local-name()='Vendor_Payments' and namespace-uri()='']/*[local-name()='Payment_Info' and namespace-uri()='']/*[local-name()='Payment_Run_ID' and namespace-uri()='']' contains more than a single node. 

    XML looks good to me with 3 nodes of Payment_Info

    Wednesday, November 12, 2014 10:11 PM
  • A valid xml should always have one root. For e.g.

    <Vendor_Payment>
    <Payment_Info>
    <Payment_Run_ID>10</Payment_Run_ID>
    </Payment_Info>
    <Payment_Info>
    <Payment_Run_ID>11</Payment_Run_ID>
    </Payment_Info>
    </Vendor_Payment>

    is valid XML, and 

    <Payment_Info>
    <Payment_Run_ID>10</Payment_Run_ID>
    </Payment_Info>
    <Payment_Info>
    <Payment_Run_ID>11</Payment_Run_ID>
    </Payment_Info>

    is invalid.

    If you are sure about which ID you need you can use index to select using [n], and if you need to iterate through, you will need to assign valid xml to the XmlDocument (may be change xpath to nevigate to parent which hax Max Occur =1.

    fyi: you can't send invalid xml to sendport using XmlTransmit like you can't assign invalid xml to XmlDocument


    Please mark it as Answer if this answers your question
    Thanks.
    Mo
    The contents I write here is my personal views, not the view of my employer and anyone else.



    • Edited by Mohan Raj Aryal Wednesday, November 12, 2014 11:49 PM
    • Marked as answer by Angie Xu Tuesday, November 18, 2014 1:42 AM
    Wednesday, November 12, 2014 11:48 PM
  • It seems like it is not passing the XML validation. Tried to send out the message from ODX using send port with XmlTransmit pipeline, getting following error:

    Inner exception: The result set for the XPath expression '/*[local-name()='Vendor_Payments' and namespace-uri()='']/*[local-name()='Payment_Info' and namespace-uri()='']/*[local-name()='Payment_Run_ID' and namespace-uri()='']' contains more than a single node. 

    XML looks good to me with 3 nodes of Payment_Info

    1) As your inner exception says that there are multiple nodes being returned with the xpath you are using. Check whether you are assigning the result to a single node or an array of nodes. In case you are assigning the result to a single node, change it to an array and process accordingly.

    <o:p>If you wish to assign the output of the XPath expression to a single node only, make use of below expression. This will extract first record instance using XPath "position()" function.

     '/*[local-name()='Vendor_Payments' and namespace-uri()='']/*[local-name()='Payment_Info' and namespace-uri()=''] and position()=1]/*[local-name()='Payment_Run_ID' and namespace-uri()='']' 

    2) For the error: Inner exception: "Cannot use XLANGMessage.RetrieveAs to convert message part part with type Payments.Schemas.Vendor_Payments_BAM to type System.Xml.XmlDocument."

    RetrieveAs method exposed by the XLANGPart class is not able to desterilize the content of the message part and creates an instance of the System.Xml.XmlDocument because it’s not a valid XML returning more than 1 root node.

    Rachit



    Thursday, November 13, 2014 2:56 AM
    Moderator
  • I think your schema structure is not correct ,Try to check whether you have Valid Schema ? If so either you can retrieve message from

    XmlDocument XmlDocMsg = (XmlDocument)msg[0].RetrieveAs(typeof(XmlDocument));

    Or you can serialize the schema into Object through xsd.exe and do something like this

    XmlSerializer xs = new XmlSerializer(typeof(MySchemaType));
    
    MySchemaType st = (MySchemaType)xs.Deserializer(myXlangMessage[0].RetrieveAs(typeof(XmlReader)));

    Thanks

    Abhishek


    Thursday, November 13, 2014 4:29 AM
  • Hi Abhishek,

    I have serialized my schema into object through xsd.exe

    and in my helper class

    MySchemaTyep st=

    (MySchemaTyep )XlangMsg[0].RetrieveAs(typeof(MySchemaTyep ));

    but I am stil getting the above error

    Can you Please help me with this?


    Thursday, March 24, 2016 8:32 AM