Click here to Skip to main content
15,885,546 members
Articles / Programming Languages / Visual Basic

Passing WCF Transactions to COM+

Rate me:
Please Sign up or sign in to vote.
4.89/5 (2 votes)
28 Aug 2012CPOL4 min read 19.3K   165   7  
This article provides a program to demonstrate how to pass WCF transactions to COM+.
<?xml version="1.0" encoding="utf-8"?>
<root>
  <!-- 
    Microsoft ResX Schema 
    
    Version 2.0
    
    The primary goals of this format is to allow a simple XML format 
    that is mostly human readable. The generation and parsing of the 
    various data types are done through the TypeConverter classes 
    associated with the data types.
    
    Example:
    
    ... ado.net/XML headers & schema ...
    <resheader name="resmimetype">text/microsoft-resx</resheader>
    <resheader name="version">2.0</resheader>
    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
        <value>[base64 mime encoded serialized .NET Framework object]</value>
    </data>
    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
        <comment>This is a comment</comment>
    </data>
                
    There are any number of "resheader" rows that contain simple 
    name/value pairs.
    
    Each data row contains a name, and value. The row also contains a 
    type or mimetype. Type corresponds to a .NET class that support 
    text/value conversion through the TypeConverter architecture. 
    Classes that don't support this are serialized and stored with the 
    mimetype set.
    
    The mimetype is used for serialized objects, and tells the 
    ResXResourceReader how to depersist the object. This is currently not 
    extensible. For a given mimetype the value must be set accordingly:
    
    Note - application/x-microsoft.net.object.binary.base64 is the format 
    that the ResXResourceWriter will generate, however the reader can 
    read any of the formats listed below.
    
    mimetype: application/x-microsoft.net.object.binary.base64
    value   : The object must be serialized with 
            : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
            : and then encoded with base64 encoding.
    
    mimetype: application/x-microsoft.net.object.soap.base64
    value   : The object must be serialized with 
            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
            : and then encoded with base64 encoding.

    mimetype: application/x-microsoft.net.object.bytearray.base64
    value   : The object must be serialized into a byte array 
            : using a System.ComponentModel.TypeConverter
            : and then encoded with base64 encoding.
    -->
  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
    <xsd:element name="root" msdata:IsDataSet="true">
      <xsd:complexType>
        <xsd:choice maxOccurs="unbounded">
          <xsd:element name="metadata">
            <xsd:complexType>
              <xsd:sequence>
                <xsd:element name="value" type="xsd:string" minOccurs="0" />
              </xsd:sequence>
              <xsd:attribute name="name" use="required" type="xsd:string" />
              <xsd:attribute name="type" type="xsd:string" />
              <xsd:attribute name="mimetype" type="xsd:string" />
              <xsd:attribute ref="xml:space" />
            </xsd:complexType>
          </xsd:element>
          <xsd:element name="assembly">
            <xsd:complexType>
              <xsd:attribute name="alias" type="xsd:string" />
              <xsd:attribute name="name" type="xsd:string" />
            </xsd:complexType>
          </xsd:element>
          <xsd:element name="data">
            <xsd:complexType>
              <xsd:sequence>
                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
              </xsd:sequence>
              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
              <xsd:attribute ref="xml:space" />
            </xsd:complexType>
          </xsd:element>
          <xsd:element name="resheader">
            <xsd:complexType>
              <xsd:sequence>
                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
              </xsd:sequence>
              <xsd:attribute name="name" type="xsd:string" use="required" />
            </xsd:complexType>
          </xsd:element>
        </xsd:choice>
      </xsd:complexType>
    </xsd:element>
  </xsd:schema>
  <resheader name="resmimetype">
    <value>text/microsoft-resx</value>
  </resheader>
  <resheader name="version">
    <value>2.0</value>
  </resheader>
  <resheader name="reader">
    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
  </resheader>
  <resheader name="writer">
    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
  </resheader>
  <data name="SqlCreateTableLog" xml:space="preserve">
    <value>IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Log]') AND type in (N'U'))
DROP TABLE [dbo].[Log]
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Log_Audit]') AND type in (N'U'))
DROP TABLE [dbo].[Log_Audit]

CREATE TABLE [dbo].[Log](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[Deleted] [bit] NOT NULL,
	[TraceVersion] [int] NOT NULL,
	[UTimeStamp] [datetime] NOT NULL,
	[Entry] [varchar](256) NOT NULL,
 CONSTRAINT [PK_Log] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

CREATE TABLE [dbo].[Log_Audit](
	[Id] [int] NOT NULL,
	[Deleted] [bit] NOT NULL,
	[TraceVersion] [int] NOT NULL,
	[UTimeStamp] [datetime] NOT NULL,
	[Entry] [varchar](256) NOT NULL,
 CONSTRAINT [PK_Log_Audit] PRIMARY KEY CLUSTERED 
(
	[Id] ASC,
	[Traceversion] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]</value>
  </data>
  <data name="SqlCreateTriggerLog" xml:space="preserve">
    <value>CREATE TRIGGER [dbo].[trLog_AUDIT_UD] ON [dbo].[Log]
AFTER UPDATE, DELETE
AS 
DECLARE @ErrorMessage NVARCHAR(MAX) 
DECLARE @ErrorSeverity INT 
DECLARE @ErrorState INT 
/* IF NO ROWS WERE AFFECTED, DO NOTHING */
IF @@ROWCOUNT=0
BEGIN
	RETURN
END 
 
SET NOCOUNT ON
 
DECLARE	@Counter INT, @Now DATETIME
SET @Now = GETDATE()
/****************************************************/
/* Check out the action (Update or Delete) 		    */
/****************************************************/
SELECT	@Counter = COUNT(*)
FROM	INSERTED
IF @Counter = 0 --&gt; DELETE
BEGIN
	RAISERROR('DELETE action is prohibited for Log',16,10)
	RETURN
END
/* Insert Previous Record to Audit */
BEGIN TRY 
	INSERT INTO Log_Audit(
		[Id]
		, [TraceVersion]
		, [Deleted]
		, [UTimeStamp]
		, [Entry]
	)
	SELECT  			
		d.[Id]
		, d.[TraceVersion]
		, d.[Deleted]
		, d.[UTimeStamp]
		, d.[Entry]
	FROM DELETED d
END TRY 
BEGIN CATCH 
    SELECT 
		@ErrorMessage = ERROR_MESSAGE(), 
		@ErrorSeverity = ERROR_SEVERITY(), 
		@ErrorState = ERROR_STATE() 
    RAISERROR (@ErrorMessage, @ErrorSeverity, @ErrorState) 
    RETURN 
END CATCH 

/* UPDATE MASTER RECORD TRACEVERSION, UTIMESTAMP */ 
BEGIN TRY 
    UPDATE 	main
    SET 	main.TraceVersion = d.TraceVersion + 1, main.UTimeStamp = @Now
    FROM Log main 
    INNER JOIN DELETED d ON d.Id = main.Id
    INNER JOIN INSERTED i ON i.[Id] = main.[Id]
END TRY 
BEGIN CATCH 
    SELECT 
		@ErrorMessage = ERROR_MESSAGE(), 
		@ErrorSeverity = ERROR_SEVERITY(), 
		@ErrorState = ERROR_STATE() 
    RAISERROR (@ErrorMessage, @ErrorSeverity, @ErrorState)
    RETURN 
END CATCH 

/* PROCESS ONLY DELETED ROWS FROM NOW ON */ 
IF NOT EXISTS(SELECT 1 FROM inserted WHERE Deleted = 1) 
    RETURN 
/* RE-INSERT LAST UPDATED MASTER RECORD INTO AUDIT TABLE WHERE Deleted = 1 */ 
BEGIN TRY 
    INSERT INTO Log_Audit(
		[Id]
		, [TraceVersion]
		, [Deleted]
		, [UTimeStamp]
		, [Entry]
	)
    SELECT  			
		d.[Id]
		, d.[TraceVersion]
		, d.[Deleted]
		, d.[UTimeStamp]
		, d.[Entry]
    FROM Log d
    INNER JOIN INSERTED i ON d.Id = i.Id
    WHERE ISNULL(i.Deleted, 0) = 1
END TRY 
BEGIN CATCH 
    SELECT 
		@ErrorMessage = ERROR_MESSAGE(), 
		@ErrorSeverity = ERROR_SEVERITY(), 
		@ErrorState = ERROR_STATE() 
    RAISERROR (@ErrorMessage, @ErrorSeverity, @ErrorState) 
    RETURN 
END CATCH 

BEGIN TRY 
	/* DELETE MASTER RECORD */
    DELETE c
    FROM Log c
    INNER JOIN INSERTED i ON c.Id = i.Id
    WHERE ISNULL(i.Deleted, 0) = 1
END TRY 
BEGIN CATCH 
    SELECT 
		@ErrorMessage = ERROR_MESSAGE(), 
		@ErrorSeverity = ERROR_SEVERITY(), 
		@ErrorState = ERROR_STATE() 
    RAISERROR (@ErrorMessage, @ErrorSeverity, @ErrorState) 
    RETURN 
END CATCH</value>
  </data>
</root>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Unisystems
Greece Greece
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions