Integrating WCF and Enterprise Services C# Help

Windows Communication Foundation (WCF) is a new communication technology that is part of .NET Framework 3.0. WCF is covered in detail in Chapter 42, “Windows Communication Foundation.” .NET Enterprise Services offers a great integration model with WCF.

WCF Service Facade

Adding a WCF facade to an Enterprise Services application allows using WCF clients to access the serviced components. Instead of using the DCOM protocol, with WCF you can have different protocols such as HTTP with SOAP or TCP with a binary formatting.

You can create a WCF facade from Visual Studio 2008 by selecting Tools I¢ WCF Svc Config Editor.. With this tool started select File of Integrate of COM+ Application. Select the COM+ Application Wrox. NorthwindDemo, the component Wrox. ProCSharp. Enterprise Services. OrderControl, and the interface IOrderControl as shown in Figure 44-10.

Instead of using Visual Studio to create the WCF facade, you can use the command-line utility comsvccconfig .exe. You can find this utility in the directory <windows> Microsoft .NET\ Framework\v3.0\Windows Communication Foundation.

Figure 44-10

Figure 44-10

With the next dialog you can select all the methods from the interface IOrderControl that should be .available to WCF clients. With the interface IOrderControl just one method, NeWOrder() is shown.

The next dialog shown in Figure 44-11 allows configuration of the hosting options. With the hosting option, you can specify in which process the WCF service should run. When you select the COM+ hosted option, the WCF facade runs within the dllhost.exe process of COM+. This option is possible only if the application is configured as a server application: [ApplicationActivation (Activat.Lonopt Lon. Server) ]. The Web hosted it is specifies that the WCF channel is listens inside a process of the ITS or WAS (Windows Activation Services) worker process. WAS is new with Windows Vista and Windows Server 2008. Selecting “Web hosted in-process” means that the library of the Enterprise Services component runs within the ITS or WAS worker process. This configuration is possible only if the application is “configured as a library application.(ApplicationActivation(ActivationOption.Library).

Selecting the “Add MEXendpoint” option adds a MEX(Metadata Exchange) endpoint to the WCF configuration file, so that the client programmer can access the metadata of the service using WS-Metadata Exchange.

MEX is explained in Chapter 42, “Windows Communication Foundation.”

Figure 44-11

Figure 44-11

With the next dialog shown in Figure 44-12 you can specify the communication mode to access the WCF facade. Depending on your requirements, if the client is accessing the service across a firewall or platform-independent communication is required, HTTP is the best choice. TCP offers faster communication across machines for .NET clients, and Named Pipes is the fastest option if the client
application is running on the same system as the service. .

Figure 44-12

Figure 44-12

The next dialog requests information about the base address of the service that depends on the communication protocol selection, as shown in Figure 44·13.

Figure 44-13

Figure 44-13

The last dialog shows the location of the end point configuration. The base directory for the configurations is <Program Files>\ComPlus Applications followed by the unique ID of the application.In this directory you can find the file application.config. This configuration file lists the behaviors and end points for WCE

The <service> element specifies the exposed WCF service with the endpoint configuration. The binding isset to wsHttpBinding with a com TransactionalBinding configuration, so transactions can flow from the caller the serviced component. With other network and client requirements, you can specify a different binding, but this is all covered in Chapter 42.

Before you can start the server application you need to change the security to allow the user that runs the application to register ports for listening. Otherwise a normal user is not allowed to register a listener port. On Windows Vista you can do this with the netsh command as shown. The option http changes the ACL for the HTTP protocol. The port number and the name of the service are defined with the URL, and the user option specifies the name of the user that starts the listener service.

netsh http urlacl url=http://+:8088/NorthwindService user=username

Client Application

Create a new console application named WCF Client  App. Because the service offers a MEX endpoint, you can add a service reference from Visual Studio by selecting project ¢ Add Service Reference (see Figure 44-14).

If the service is COM+ hosted, you have to start the application before you can access the MEX data. If the service is hosted inside WAS, the application is started automatically.

Figure 44-14

With the service reference a proxy class is created, the assemblies System. ServiceModel and System. Runtime. Serialization are referenced, and an application configuration file referencing the service is added to the client application.

Now, you can use the generated entity classes and the proxy class OrderControlClient to send an order request to the serviced component;

Posted on October 31, 2015 in Enterprise Services

Share the Story

Back to Top
Share This