Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 12th, 2004, 09:06 PM
Authorized User
 
Join Date: Jun 2003
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default Transaction/Reflection

using System;
using System.Reflection;

namespace test
{
    public class Controller
    {
        //...
        public XmlDocument execute(XmlDocument oXml)
        {
            //this method receive a Xml string, materializes an instance of an object and invoke a method requested in this Xml (through Reflection)
            //in this case the instance created is a Person object and the method called is add(save a object in a Relational DataBase)
        }
    }
}


using System;
using System.EnterpriseServices;

namespace test
{
    public class Client : ServicedComponent
    {
        //...
    }
}


using System;
using System.EnterpriseServices;

namespace test
{
    [Transaction(TransactionOption.Required)]
    public class Person : Client
    {
        //...
        public void add(Object oObj)
        {
            PersistenceBroker broker = new PersistenceBroker();
            Person person;
            Address address;
            try
            {
                person = (Person)oObj;
                address = person.getAddress();
                broker.add(person);
address.setIdClient(person.getIdClient());
                address.add(address);
                ContextUtil.SetComplete()
            }
            catch(Exception err)
            {
                ContextUtil.SetAbort()
                throw new Exception(err.Message, err);
            }
        }
    }
}


using System;
using System.EnterpriseServices;

namespace test
{
    [Transaction(TransactionOption.Required)]
    public class Address : ServicedComponent
    {
        //...
        public void add(Object oObj)
        {
            PersistenceBroker broker = new PersistenceBroker();
            Address address;
            try
            {
                address = (Address)oObj;
                broker.add(address);
                ContextUtil.SetComplete()
            }
            catch(Exception err)
            {
                ContextUtil.SetAbort()
                throw new Exception(err.Message, err);
            }
        }
    }
}


using System;
using System.Reflection;
using System.EnterpriseServices;

namespace test
{
    [Transaction(TransactionOption.Supported)]
    public class PersistenceBroker
    {
        //...
        public void add(Object oObj)
        {
            //through reflection this method creates a string with INSERT command and
            //with ADO .Net this command is executed
        }
    }
}

This code seems that Ok, but after invocation of the method the object instanced doesn’t exist anymore and I need the ID's returned in this object passed by reference.

Look if I don't use ContextUtil (or [AutoComplete]) in the Person and Address classes this error doesn't appear.


Fabio Ferreira Balota
__________________
Fabio Ferreira Balota
 
Old October 6th, 2007, 04:28 PM
Authorized User
 
Join Date: Dec 2004
Posts: 68
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to DZukiewicz
Default

Look into TransactionScope class, you are using a .NET 1.1 approach methinks.

Regards,

Dom
 
Old October 6th, 2007, 04:54 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
quote: you are using a .NET 1.1 approach methinks.
Maybe that's because this post is from January 2004? .NET 2,0 didn't exist back then.

Please check the dates of the post you are replying to. I could be wrong, but generally I don't think there's much point reviving posts that are three or four years old....

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004





Similar Threads
Thread Thread Starter Forum Replies Last Post
Using System.Reflection maxl Pro Visual Basic 2005 0 March 21st, 2007 05:42 PM
Reflection-TargetInvocationException dipak_2111 C# 2005 0 January 11th, 2007 01:08 AM
Reflection jayakumar.cj ASP.NET 1.0 and 1.1 Basics 1 July 15th, 2006 06:12 AM
Reflection Events CrazyLegsCooper VS.NET 2002/2003 4 September 8th, 2005 10:06 PM
Reflection ffbalota C# 2 January 8th, 2004 03:07 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.