Data loss when returning Serializable object to biztalk

518 views Asked by At

My project has an orchestration which contains a non-transactional scope.

Inside that scope, there is a call to .NET helper in order to get a Hashtable with values.

It's important to mention that it is the ONLY thing I perform in that scope, means that scope contains only expression shape which calls the .NET function.

The function which returns the Hashtable is marked as static.

It looks like this:

public static Hashtable GetKeys(XmlDocument xmlDoc)
        {
            Hashtable servicesKey = new Hashtable();

            //Key1
            int keysCounter = 1;

            // Add key1
            servicesKey.Add("Key" + keysCounter, Constants.Keys.First);
            keysCounter++;

            // Add key2
            servicesKey.Add("Key" + keysCounter, Constants.Keys.Second);
            keysCounter++;

            // Add key3
            servicesKey.Add("Key" + keysCounter, Constants.Keys.Third);
            keysCounter++;

            return servicesKey;
        }

For some reason, when sending a huge mass of message AND restarting the host instances in the same time - I get as a result an empty Hashtable on SOME of the messages.

Can someone please assist on how I can change it so messages won't get lost in that situation ?

2

There are 2 answers

0
James Rosser On

You need to properly serialize your class in order to guarantee the data will persist correctly.

First you need to give your class the serializable tag:

[Serializable]
public class MyClass
{
    public Hashtable GetKeys(XmlDocument xmlDoc)
    {
        // etc...
    }
}

Then you need to instantiate an instance of it in your orchestration. You do this by creating a variable and assigning it the type of your class (you must reference the assembly containing the class in the biztalk project with the orchestration.)

You can then declare a new instance in an expression shape:

// In an expression shape:
MyOrchestrationVariable = new MyExternalAssembly.MyClass();

And call your method safely:

// In an expression shape again:
ServicesKey = MyOrchestrationVariable.GetKeys(XmlDoc);

Hope this helps.

0
Prabhdeep Gill On

I don't get it, what does this means, and restarting the host instance. Are you restarting the host instance after submitting the message? why so?

Regarding returning empty hashtags, try to test that code separately inside console app and see how it behaves for "huge mass of messages". Another suggestion is, design your process in way that each message (among mass) creates new instance of Orch and hence will instantiate .NET class also separately.