NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

Marking a ComEmulate Custom Attribute

You can include COM+ 1.0 services in your NGWS classes by marking the class with the ComEmulate custom attribute. This attribute guarantees that the NGWS execution environment will create each object of a marked class using standard COM interoperability.

For the PDC Technology Preview, the NGWS runtime has same fidelity as COM. For the product release, the runtime will provide the same rich object-model fidelity that exists in the NGWS runtime.

Objects from a class marked with the ComEmulate attribute are created in the current appdomain of the executing thread and behave as though they have not aggregated the free threaded marshaler.

The following example shows how to implement the ComEmulate attribute within a NGWS class. In this example, the EmulAccount class is configured to require a transaction and points to the Account class for its implementation.

// -----------------------------------------------------------------
// Component.cs
// -----------------------------------------------------------------
using System;
using System.Runtime.InteropServices;
using Microsoft.ComServices;

[guid("CE2A4888-82BD-40ad-9BBA-8D129747886F")]
[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)]
public interface IAccount
{
   void Debit(int amount);
}

[guid("557B96C4-F7E6-4d48-BBC3-10981E0CA664")]
[ComEmulate("Component.Account")]
[Transaction(TransactionOption.Required)]
public class EmulAccount
{
}

[guid("871D8D5C-ECC6-40a5-BD82-D5E3B1740095")]
internal class Account : IAccount
{
  public void Debit(int amount)
  {
     //… do some Db work
     if (ok) ContextUtil.SetComplete();
     else ContextUtil.SetAbort();
  }
}

See Also

InterfaceTypeAttribute Class