none
Assign value from message to schema filed in Expression shape in Orchestration. RRS feed

  • Question

  • Hi All,

    I have implemented a C# Component, this component is having Interface and classes.

    I am passing a number to this component and this will call internaly a validation will populate few fields and sendign back the collection as follows

    Component.IsValid of type bool

    Component.ErrorDetails.Details.ErrorCode of type string. 

    Component.ErrorDetails.Details.ErrorDetails of type string.

    Component.ErrorDetails.Details.ErrorHeader of type string.

    now i want to call this c# component in Expression or any other shape and wan't to assign it to schema fields

    my schema is look like as follows :

    How can i do this ? in orchestration ?


    Thanks and Regards, Nitin.

    Wednesday, September 16, 2015 3:24 AM

Answers

  • Ok Nitin,

    Then why not to pass the xml document for ValidationResponse message to the custom method and iterate through the xelement and then assign it to object .It will be much more easy . Or you can use GetElementsByTagName from the xmldocument to get the required field

    XmlNodeList elemList = doc.GetElementsByTagName("title");

    Sample method you can find on MSDN

    https://msdn.microsoft.com/en-us/library/dc0c9ekk(v=vs.110).aspx

    Thanks

    Abhishek

    • Proposed as answer by Angie Xu Thursday, September 24, 2015 2:36 AM
    • Marked as answer by Angie Xu Monday, September 28, 2015 2:58 AM
    Wednesday, September 16, 2015 6:42 AM

All replies

  • Hello,

    you can call an external assembly from biztalk and xlangs inside an orchestration.

    If you have an external assembly with methods, you can call it by doing the following:

    1. In your orchestration project, add a reference to the assembly you want to call.
    2. In the orchestration viewer, add a new variable and in the type property you can select a .NET class
    3. The select artefact type window opens in visual studio and then go the the referenced assembly
    4. Select the typename you want to use and press "OK".
    5. Drag an expression shape to the orchestration designer surface and from there you can start using the methods in the class.

    You can also refer: Calling External Assemblies From Orchestrations


    Please mark as answer or vote as helpful if my reply does

    Wednesday, September 16, 2015 3:50 AM
    Moderator
  • Hi Nitin,

    You cannot assign collection values into the schema fields inside Orchestration. Here is what you can do :

    -> Generate a class of your schema using XSD.exe.

    -> Create a new object of this class into your component and populate the fields of your schema there.

    -> Return the object of your schema class back and serialize it.

    Here is the sample code of the serializing an object.

     public static void Serialize(object value)
            {
                XmlDocument document = null;
                try
                {
                    if (value != null)
                    {
                        XmlSerializer xmlSerializer = new XmlSerializer(value.GetType());
                        StringBuilder sb = new StringBuilder();
                        StringWriter writer = new StringWriter(sb, CultureInfo.InvariantCulture);
                        xmlSerializer.Serialize(writer, value);
                        document = new XmlDocument();
                        document.LoadXml(sb.ToString());
                    }
                }
    }

    Please indicate "Mark as Answer" or "Mark as Helpful" if this post has answered the question

    Regards

    Rahul Madaan

    biztalkvillage.blogspot.com

    Wednesday, September 16, 2015 4:08 AM
  • Hi Nitin ,

    You can use the following ways to get Validation error message populated inside the Orchestration /

    Step1 ) Use the xsd.exetool in the SDK to generate an XSD schema from the class and all classes used by that class. The -t switch tells the program only to generate a schema for one particular type in the test.exe file:
    xsd.exe -t:ValidationResponse MyAssemlby.dll

    https://msdn.microsoft.com/en-us/library/5s2x1sy7(v=vs.110).aspx

    Step2 ) retun xmldocument from the custom method using class object (you need to define method for this in your assembly )

    Refer :http://stackoverflow.com/questions/2548708/how-to-create-an-xml-document-from-a-net-object

    Step3 ) create a message with generated xsd and assign the xmldocument to the newly created message.

    Step4 ) Assign value to new message using xpath .

    Thanks

    Abhishek

                                                                                                

    Wednesday, September 16, 2015 4:10 AM
  • Hi Nitin,

    If you always have single  "ErrorDetails" node then you can promote all the schema fields as distinguished properties and assign the values to them after getting from c# method.

    Cheers


    JB

    Wednesday, September 16, 2015 4:11 AM
  • No JB,

    i will have collection of ErrorDetails.


    Thanks and Regards, Nitin.

    Wednesday, September 16, 2015 5:30 AM
  • Hi Abhishek,

    What i am trying to achieve her is that...

    from ValidationResponse.xsd file i have created .cs file

    this will be act as a DTO for me.

    I have Interface with one method in it .

    There will be two validation on number passing to this C# components.

    1) check length 2) mathematical calculation(algorithm)).

    For these to validation i have created two class files which will inherit this Interface and will implement the interface method.

    there is one more actual implementation file which will call it as a array 


    Thanks and Regards, Nitin.

    Wednesday, September 16, 2015 6:23 AM
  • Ok Nitin,

    Then why not to pass the xml document for ValidationResponse message to the custom method and iterate through the xelement and then assign it to object .It will be much more easy . Or you can use GetElementsByTagName from the xmldocument to get the required field

    XmlNodeList elemList = doc.GetElementsByTagName("title");

    Sample method you can find on MSDN

    https://msdn.microsoft.com/en-us/library/dc0c9ekk(v=vs.110).aspx

    Thanks

    Abhishek

    • Proposed as answer by Angie Xu Thursday, September 24, 2015 2:36 AM
    • Marked as answer by Angie Xu Monday, September 28, 2015 2:58 AM
    Wednesday, September 16, 2015 6:42 AM
  • So, DTO, Serialized classes, inheritance.  I think you're making this a lot more complicated than it needs to be.

    A better pattern would be for your validation component to maintain the ValidationResponse Xml instance internally.

    Then at the end of the process, you call like getValidationResults() to get the XmlDocument.

    Wednesday, September 16, 2015 11:07 AM
    Moderator