从UniObjects.NET访问UniData的多个线程抛出UNI RPC错误

时间:2011-12-01 15:32:53

标签: .net rpc biztalk-2010 unidata uniobjects

我们一直在使用UniObjects.NET,直到我们开始使用BizTalk这是一个多线程产品。问题是下面的错误。此错误仅发生在第二个线程(可能是第3个,第4个等线程)。第一个线程连接并且能够从UniData中检索数据就好了。错误并没有多说,搜索只返回一个不处理我们特定问题的结果。有没有人有一个anwser或能指出我正确的方向?此错误没有打开连接池,我们没有使用连接池,因为它会引发其他错误。

另外需要注意的是,在调试过程中我们编写了一些代码,每个线程都会将一些调试信息写入单独的文件中。只是将调试信息写入文件的行为使两个线程都正常工作。我不认为这是一个连接计时问题(即同时打开UniSession),因为它只是在同时访问UniData文件时失败(假设同时)。

我们正在使用的UniObjects.NET的2.2.3.7377(2010年5月)文件版本的UniObjects.NET document。 UniData版本是7.2。

UPDATE:还尝试使用UniObjects.NET 2.2.5.7463版本,它仍然会抛出同样的异常。

Inner exception: GetX - Error with file 'MYFILEX'. [IBM U2][UODOTNET - UNIRPC][ErrorCode=81004] An argument was requested from the RPC that was of an invalid type

Exception type: Exception
Source: MyBusinessObjects
Target Site: System.Collections.Generic.List`1[MyBusinessObjects.XResponse] GetX(System.Collections.Generic.List`1[MyBusinessObjects.Lookup])
The following is a stack trace that identifies the location where the exception occured
  at MyBusinessObjects.Lookups.GetX(List`1 Lookups)
  at MyBusinessObjects.Integration.GetXResponses(XmlDocument xml, String header, String gheader)
  at Orchestrations.XProcess.segment1(StopConditions stopOn)
  at Microsoft.XLANGs.Core.SegmentScheduler.RunASegment(Segment s, StopConditions stopCond, Exception& exp)

UPDATE:处理阅读清单时出现相同错误。

Inner exception: [IBM U2][UODOTNET - UNIRPC][ErrorCode=81004] An argument was requested from the RPC that was of an invalid type

Exception type: UniRPCPacketException
Source: 
UniRPCPacket Class
Target Site: Byte[] ReadByteArray(Int32)
The following is a stack trace that identifies the location where the exception occured

   at IBMU2.UODOTNET.UniRPCPMessage.ReadByteArray(Int32 anIndex)
   at IBMU2.UODOTNET.UniSelectList.ReadList()
   at IBMU2.UODOTNET.UniSelectList.ReadListAsStringArray()
   at MyBusinessObjects.Lookups.GetY()
   at MyBusinessObjects.Integration.GetResponses(XmlDocument xml, String header, String gsheader)
   at Orchestrations.Process.segment1(StopConditions stopOn)
   at Microsoft.XLANGs.Core.SegmentScheduler.RunASegment(Segment s, StopConditions stopCond, Exception& exp)

1 个答案:

答案 0 :(得分:0)

此问题已解决。现在你可以使用最新的UO.NET,我希望这个问题得到解决。 您还可以使用名为“U2 Toolkit for .NET”的新Rocket软件产品。这是一个集成的解决方案,包含ADO.NET,UO.NET和LINQ to Entity功能。 要测试多线程,可以使用以下代码(而不是BiZtalk Server)。 我们使用了PLINQ和U2 Toolkit for .NET。

class Program
{
    static int NumberofThreads = 20;
    const string uniFileName = "PRODUCTS";
    static UniFile file = null;
    static UniSession session = GetUniSession();
    // setup ok/error counters
    static int ok = 0;
    static int error = 0;
    static void Main(string[] args)
    {
        // connect with no locks
        session.BlockingStrategy = UniObjectsTokens.UVT_WAIT_LOCKED;
        session.LockStrategy = UniObjectsTokens.UVT_NO_LOCKS;
        session.ReleaseStrategy = UniObjectsTokens.UVT_WRITE_RELEASE;
        Stopwatch watch = new Stopwatch();
        watch.Start();
        // take only 20 distinct record ids
        List<string> recordIds = new List<string>(RecordIds());
        // run as parallel
        Parallel.ForEach(recordIds, x =>
        {
            try
            {
                // connect to UniData CM file
                var file2 = session.CreateUniFile(uniFileName);
                // read individual record id
                file2.Read(x);
                file2.Close();
                Interlocked.Increment(ref ok);
                Console.WriteLine("rec id:" + x);
            }
            catch (Exception ex)
            {
                Interlocked.Increment(ref error);
                Console.WriteLine("Claim: {0}. Error: {1}", x, ex.Message);
            }
        });
        // set count & setup threads
        int count = 0;
        watch.Stop();
        // write error
        Console.WriteLine("Time: {2}, Count: {3}, OK: {0}, Error: {1}", ok, error, watch.Elapsed, count);
        Console.WriteLine("Press any key to exit.");
        Console.ReadKey();
    }
    static UniSession GetUniSession()
    {
        U2ConnectionStringBuilder conn_str = new U2ConnectionStringBuilder();
        conn_str.UserID = "user";
        conn_str.Password = "pass";
        conn_str.Server = "localhost";
        conn_str.Database = "XDEMO";
        conn_str.ServerType = "UNIDATA";
        conn_str.AccessMode = "Native";   // FOR UO
        conn_str.RpcServiceType = "udcs"; // FOR UO
        conn_str.Pooling = false;
        string s = conn_str.ToString();
        U2Connection con = new U2Connection();
        con.ConnectionString = s;
        con.Open();
        Console.WriteLine("Connected.........................");
        U2.Data.Client.UO.UniSession us1 = con.UniSession;
        if (file == null)
        {
            file = us1.CreateUniFile(uniFileName);
        }
        return us1;
    }

    public static List<string> RecordIds()
    {
        List<string> lRECIDList = new List<string>();
        UniSelectList sl = session.CreateUniSelectList(2);

        // Select UniFile
        UniFile fl = session.CreateUniFile("PRODUCTS");
        sl.Select(fl);

        bool lLastRecord = sl.LastRecordRead;
        int lIndex = 0;
        while (!lLastRecord)
        {
            string s4 = sl.Next();
            lRECIDList.Add(s4);
            //Console.WriteLine("Record ID:" + s4);
            lLastRecord = sl.LastRecordRead;
            lIndex++;
            if (lIndex >= NumberofThreads)
            {
                break;
            }
        }
        return lRECIDList;

    }
}