Client Application


After building the serviced component library, you can create a client application. This can be as simple as a C# console application. After you’ve created the project for the client, you have to reference both the assembly from the serviced component, SimpleServer, and the assembly System .EnterpriseServices. Then you can write the code to instantiate a new SimpleComponent instance and invoke the method Welcome(). In the following code, the Welcome() method is called 10 times. The using statement helps to release the resources allocated with the instance before the garbage collector takes action. With the using statement, the Dispose() method of the serviced component is called when the scope of the using statement ends.

  using System; namespace Wrox.ProCSharp.EnterpriseServices {    class Program    {       static void Main()       {          using (SimpleComponent obj = new SimpleComponent())          {             for (int i = 0; i < 10; i++)             {                Console.WriteLine(obj.Welcome("Katie"));             }          }       }    } } 

If you start the client application before configuring the server, the server will be configured automatically. The automatic configuration of the server is done with the values that you’ve specified using attributes. For a test you can unregister the serviced component and start the client again. If the serviced component is configured during the start of the client application, the startup needs more time. Remember that this feature is only useful during development time.

While the application is running, you can monitor the serviced component with the Component Services Explorer. By selecting Components in the tree view and choosing View image from book Detail, you can view the number of instantiated objects if the attribute [EventTrackingEnabled] is set.

As you’ve seen, creating serviced components is just a matter of deriving the class from the base class ServicedComponent and setting some attributes to configure the application. Next, you see how transactions can be used with serviced components.




Professional C# 2005 with .NET 3.0
Professional C# 2005 with .NET 3.0
ISBN: 470124725
EAN: N/A
Year: 2007
Pages: 427

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net