The Artima Developer Community
Sponsored Link

.NET Buzz Forum
Databases, MSMQ, [you name a resource manager] and Services Without Components

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Christian Weyer

Posts: 616
Nickname: cweyer
Registered: Sep, 2003

Christian Weyer is an independent Microsoft MSDN Regional Director and expert for Web services.
Databases, MSMQ, [you name a resource manager] and Services Without Components Posted: Sep 14, 2004 10:41 AM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Christian Weyer.
Original Post: Databases, MSMQ, [you name a resource manager] and Services Without Components
Feed Title: Christian Weyer: Web Services & .NET
Feed URL: http://www.asp.net/err404.htm?aspxerrorpath=/cweyer/Rss.aspx
Feed Description: Philosophizing about and criticizing the brave new world ...
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Christian Weyer
Latest Posts From Christian Weyer: Web Services & .NET

Advertisement

Just another quick note from today's work:
as a lot of other people and well-known gurus have already stated - SWC (services without components) is maybe one of the most powerful and yet unknown features of.NET Enterprise Services (yeah, this COM+-y thing ...). No need for ServicedComponent and registration in the registry and COM+ catalog.

All the love and goodness can be found in the System.EnterpriseServices namespace - namely the ServiceConfig and ServiceDomain classes. E.g. to both update a SQL Server database and place a message in a transactional queue in MSMQ is as easy as some lines of code without the burden of a configured COM+ component.

using System.EnterpriseServices;
using System.Messaging;
using System.Data.SqlClient;

...

public void StoreData()
{
  ServiceConfig sc = new ServiceConfig();
  sc.Transaction = TransactionOption.Required;
  ServiceDomain.Enter(sc);
 
  try
  {
    using(SqlConnection myConnection = new SqlConnection("..."))
    {
      SqlCommand myCommand = new SqlCommand();

      MessageQueue myQueue = new MessageQueue(@".\MyQueue");
      myQueue.Send("1", "CW", MessageQueueTransactionType.Automatic);
  
      myConnection.Open();
      myCommand.Connection = myConnection;
      myCommand.CommandText = "INSERT INTO ...";
      myCommand.ExecuteNonQuery();
  
      ContextUtil.SetComplete();
    }
 
 }
  catch(System.Exception ex)
  {
    ContextUtil.SetAbort();
  }
  finally
  {
   
ServiceDomain.Leave();
  }
}

This feature works with Windows Server 2003 and Windows XP SP2, officially.
But, there is a tweak to get it working before XP SP2: Hotfix 828741. You won't see any single word about SWC mentioned there, but believe me, with this hotfix all things are good :) Thanks to Christian for this last hint.

Read: Databases, MSMQ, [you name a resource manager] and Services Without Components

Topic: Go Army Advice! Previous Topic   Next Topic Topic: More HttpCompression

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use