新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   XML论坛     W3CHINA.ORG讨论区     计算机科学论坛     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> 本版讨论.NET,C#,ASP,VB技术
    [返回] 中文XML论坛 - 专业的XML技术讨论区计算机技术与应用『 Dot NET,C#,ASP,VB 』 → Using a transacted C# component (leveraging COM+) 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 2322 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: Using a transacted C# component (leveraging COM+) 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     admin 帅哥哟,离线,有人找我吗?
      
      
      
      威望:9
      头衔:W3China站长
      等级:计算机硕士学位(管理员)
      文章:5255
      积分:18406
      门派:W3CHINA.ORG
      注册:2003/10/5

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给admin发送一个短消息 把admin加入好友 查看admin的个人资料 搜索admin在『 Dot NET,C#,ASP,VB 』的所有贴子 点击这里发送电邮给admin  访问admin的主页 引用回复这个贴子 回复这个贴子 查看admin的博客楼主
    发贴心情 Using a transacted C# component (leveraging COM+)


    发信人: Jobs (温少), 信区: DotNET        
    标  题: Using a transacted C# component (leveraging COM+)
    发信站: BBS 水木清华站 (Wed May  9 00:04:56 2001)


    Using a transacted C# component (leveraging COM+) from ASP.NET

    Scott Guthrie
    January 4, 2001

    Level: Beginner/Intermediate

      

    Several people have asked questions like "is COM+ dead", "how does  
    COM+ relate to .NET", etc. The answer is that COM+ is definitely not  
    gone. It remains and will continue to be an important part of the  
    overall programming model, and it can be fully leveraged from ASP.NET  
    and the overall .NET Framework. You can continue to create COM+  
    components using VS6 and other compilers and then call them from ASP.NET
    pages. You can also take advantage of COM+ services with new classes  
    built using the .NET Framework.  

    You will find that leveraging these services, for example: COM+  
    transactions and COM+ object pooling, has become a whole lot easier  
    using ASP.NET and the .NET Framework. For example, it is now possible to
    avoid having to manually install a transacted component using the  
    COM+ Component Services Administration tool. Instead, if you want a  
    component to support transactions, you can simply add a "Transaction"  
    attribute to the top of a class and copy the compiled component into the
    "bin" directory of your ASP.NET web application. When the class is  
    first activated, it will automatically be registered with COM+ for you,
    which means "xcopy deployment" of both non-transacted and transacted  
    components.  

    You can also now take advantage of the COM+ "AutoComplete" feature  
    within your .NET components simply by marking activating methods  
    within an "AutoComplete" attribute. Assuming no exceptions get thrown  
    during the method's execution -- the transaction will automatically  
    commit for you. If you want to force termination of a transaction,  
    simply raise or throw an exception to abort it.

    The below sample demonstrates how to build a simple transacted C#  
    class and use it within an ASP.NET page written using VB. Note that I've
    only tried this on Win2k; I'm not sure whether this works on NT4 in  
    beta1:



    Account.cs:



    using System;
    using Microsoft.ComServices;


    // COM+ app name as it appears in the COM+ catalog
    [assembly: ApplicationName("TestApp")]

    [Transaction(TransactionOption.Required)]

    public class Account : ServicedComponent  

    {

        [AutoComplete]

        public String Debit(int amount)  
        {
            // Todo: Do some Database work, throw an
            // exception to abort the transaction.
            // otherwise the transaction will commit.
            // Use the ContextUtil class to return the  
            // transaction id
            return ContextUtil.TransactionId.ToString();
        }
    }



    To compile the above class, simply execute the following code within the
    root directory of an ASP.NET application:  


    mkdir bin  
    csc /target:library /out:bin\Account.dll Account.cs
    /r:Microsoft.ComServices.dll  


    then invoke the component from the following ASP.NET Page (no  
    registration required):



    Trans.aspx:  



    <html>

      <script language="VB" runat=server>

        Sub Page_Load(Sender As Object, E as EventArgs)
            Dim MyAccount as New Account()

            TransId.Text = MyAccount.Debit(343)
        End Sub

      </script>
    <body>
        <h1>C# Transacted Component within ASP.NET</h1>
        <b> Transaction ID: </b> <asp:label id="TransId" runat=server/>
    </body>
    </html>  



    The transaction id of the completed transaction should be rendered  
    cleanly into the output. To see how the COM+ auto-registration mechanism
    worked, open up the "Component Services" admin tool within the  
    "Programs->Administrative Tools" item on the Start Menu. Expand the  
    "Component Services" tab to "Computers->My Computer" and then to "COM+  
    Applications".

    Notice the presence of the "TestApp" COM+ Application/Package. This  
    was created in response to line 4 of the Account.cs file (which had an  
    assembly attribute indicating the COM+ App name to create). Expand  
    this to see the "Account" component listed within it. Notice that the  
    properties of the component (for example: transaction=required) within  
    the admin tool match those set within the Account.cs file.

    Then click on the "Distributed Transaction Coordinator->Transaction  
    Statistics" item within the admin tool. Notice that the transaction  
    count increases each time you hit the page.

    Note that the above sample demonstrates calling a transacted component  
    from a non-transacted ASP.NET Page. Note that if you want the ASP.NET  
    page itself to be transacted as well (for example: if you were calling  
    multiple transacted components from it and wanted them to all share  
    the same transaction), simply add the <%@ Page Transaction="Required" %>
    attribute to the top of the file.


      


    --

    ※ 来源:·BBS 水木清华站 smth.org·[FROM: 210.39.3.110]
    上一篇
    返回上一页
    回到目录
    回到页首
    下一篇


       收藏   分享  
    顶(0)
      




    ----------------------------------------------

    -----------------------------------------------

    第十二章第一节《用ROR创建面向资源的服务》
    第十二章第二节《用Restlet创建面向资源的服务》
    第三章《REST式服务有什么不同》
    InfoQ SOA首席编辑胡键评《RESTful Web Services中文版》
    [InfoQ文章]解答有关REST的十点疑惑

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2004/11/9 2:25:00
     
     GoogleAdSense
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 Dot NET,C#,ASP,VB 』的所有贴子 点击这里发送电邮给Google AdSense  访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2024/5/3 10:36:50

    本主题贴数1,分页: [1]

    管理选项修改tag | 锁定 | 解锁 | 提升 | 删除 | 移动 | 固顶 | 总固顶 | 奖励 | 惩罚 | 发布公告
    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    769.531ms