This walkthrough describes how to configure, launch, and debug a sample service-oriented architecture (SOA) project on a Windows HPC Server 2008 cluster. This walkthrough helps you understand the elements of the HPC Cluster-SOA template and how to connect and configure the service and the client. It also describes how to use the debugger to follow a request from the client code to an instance of your service that is running on the cluster, then back to the client.

The following procedure adds a new Windows Communication Foundation (WCF) service to the ClusterSOASample solution that you created. For the purpose of this walkthrough, you use the default service code. The default service accepts and integer and returns a string.

The procedure includes a step to build the service library project. When you build the project, the SampleServiceLib.dll and SampleServiceLib.dll.config files are generated in the bin\Debug folder for the project.

To create and build a new WCF service

With your ClusterSOASample.sln open in Visual Studio, click File, point to Add, then click New Project.

In the Add New Project dialog box:

In Project Types, expand Visual C#, then select WCF.

In the list of templates, select WCF Service Library.

In Name, type SampleServiceLib.

Click OK.

In Solution Explorer, verify that the ClusterSOASample solution includes two projects: SampleClientApp and SampleServiceLib.

In Solution Explorer, right-click SampleServiceLib, and then click Build.

The following procedure describes how to add a service reference to the SampleClientApp project. When you add a service reference to a project in Visual Studio, the WCF client objects (client proxies) are created automatically. This procedure includes a step to generate asynchronous operations (such as BeginGetData and EndGetData) in the resulting WCF client object.

Note

A WCF client is a local object that represents a WCF service in a form that the client application can use to communicate with the remote service. WCF client types implement the target service contract, so you can use the client object directly to invoke service operations.

To add the service reference

In Solution Explorer, right-click SampleClientApp, then click Add Service Reference.

In the Add Service Reference dialog box:

Click the down arrow on the Discover button, and then click Services in Solution. After a few moments, a service URL appears under Address.

Click Go to discover the service. Service1 appears under Services.

In Namespace, type SampleServiceRef.

Click Advanced to modify the service reference settings.

In the Service Reference Settings dialog box, do the following:

Under Client, select the Generate asynchronous operations check box.

Click OK to accept the change and return to the Add Service Reference dialog box.

Click OK to add the service reference and close the dialog box.

Verify the following:

In Solution Explorer, under SampleClientApp, expand the Service References node to see the reference that you added.

Right-click SampleServiceRef, and then click View in Object Browser.

In Object Browser, expand the Client.SampleServiceRef namespace, and then click Service1Client to see the methods that are available in the WCF client object. In Step 4 of the walkthrough, you add this namespace to the using directives in the client code and then use the methods in Service1Client to invoke the service.

This procedure describes how to modify the default client code in the Program.cs file that is included with the HPC Cluster-SOA Project template. You must modify the code to specify your cluster head node and to use the WCF client object that was generated when you added the service reference.

To specify the head node and the WCF client proxy in the client code

In Solution Explorer, under SampleClientApp, double-click Program.cs.

In the Program.cs code, at the end of the using directives, type the following to add a directive for the Client.SampleServiceRef namespace:

using Client.SampleServiceRef;

In the Main function, the name of the head node and the name of the service are specified with the following code:

The following procedure describes how to add the service contract name to the configuration file for the client application. In app.config, the first endpoint element defines the HPC SOA Debugging Endpoint. The contract attribute has a placeholder value of [Service_Contract_Name]. You must replace this with the service contract name. The service contract name generated automatically when you added the service reference. In this example, the service contract name is SampleServiceRef.IService1.

Note

To verify the name of the service contract, you can view the service reference in Object Browser, and then double-click the interface to see the associated code. In the example in this walkthrough, the interface is called IService1. In the code for the interface, the service contract name is defined by the ConfigurationName as illustrated by the following line of code:

The following procedure describes how to replace the App.config file in SampleServiceLib with app.config.TemplateForService.xml. This configuration file is included in the HPC Cluster-SOA Project template. The procedure includes steps for replacing placeholder values in app.config.TemplateForService.xml for the service name and the service contract name. The service name property corresponds to the namespace and class (Namespace.Class) of the service (SampleServiceLib.Service1). The contract corresponds to the namespace and public interface (Namespace.Interface) that is offered by the service (SampleServiceLib.IService1).

To modify the service configuration file

In Solution Explorer, under SampleClientApp, right-click app.config.TemplateForService.xml, and then click Copy.

Right-click SampleServiceLib, and then click Paste. A copy of app.config.TemplateForService.xml appears in the SampleServiceLib project.

Under SampleServiceLib, right-click App.config, click Rename, and then rename the file to App.config.old. If a dialog box appears, click Yes to confirm the change.

Under SampleServiceLib, right-click app.config.TemplateForService.xml, click Rename, and then rename the file to App.config.

Double-click App.config to open the file.

In App.config, replace [Service_Name] with SampleServiceLib.Service1, and replace [Service_Contract_Name] with SampleServiceLib.IService1 so that the service attributes are defined as follows:

<services><!--Replace following [Service_Name] by the real service name--><servicebehaviorConfiguration="ServiceBehavior"name="SampleServiceLib.Service1"><!--Replace following [Service_Contract_Name] by the real service contract name--><endpointaddress="" binding="netTcpBinding"contract="SampleServiceLib.IService1"bindingConfiguration="HpcSoaDebuggingBinding"/><endpointaddress="mex"behaviorConfiguration="" binding="mexHttpBinding"contract="IMetadataExchange"/></service></services>

To step through the code during debugging, you must set breakpoints in the code. All of the debugging modes in the Cluster-SOA Debugger require a breakpoint in the service code. To follow a request from the client to the service on the cluster, and then back to the client, you must also set breakpoints in the client before you invoke the service and in the callback method.

The following procedure describes how to set breakpoints when Session.CreateSession is called, in the CallBack method of the client, and in the GetData method of the service.

To set breakpoints in Program.cs and Service1.cs

In Solution Explorer, under SampleClientApp, double-click Program.cs to open the file.

In Program.cs, set a breakpoint in following line of code:

using (Session session = Session.CreateSession(startInfo, 60 * 1000))

To set a breakpoint, right-click the line of code, point to Breakpoint, then click Insert Breakpoint.

Set a breakpoint in the CallBack method in the following line of code:

var client = result.AsyncState as Service1Client;

In Solution Explorer, under SampleServiceLib, double-click Service1.cs to open the file.

In Service1.cs, set a breakpoint in the GetData method in the following line of code:

Before you launch the debugger, you must specify the head node and the service to debug in the Cluster-SOA Debugger properties. Optionally, you can configure additional properties for the debugging session. The Cluster-SOA Debugger properties that you set are saved as part of the project file. For more information about the configuration options and default values, see How to: Configure and Launch the Cluster-SOA Debugger.

The following procedure describes how to configure and launch the Cluster-SOA Debugger for SampleClientApp. The default Debug mode enables you to follow a request end-to-end, stopping at the breakpoints that you set in the client and in the service code.

To configure the Cluster-SOA Debugger

In Solution Explorer, right-click SampleClientApp, and then click Properties.

In the properties page, click the Cluster-SOA Debug tab.

In Select a head node, select the name of your head node from the drop-down list. This is the same head node that you specified in the client code.

In Select services to debug, select SampleServiceLib.

Optionally: In Deployment folder, specify the shared folder to use for staging deployment to the cluster.

Optionally: In Working directory on each compute node, specify the working directory to use on each compute node in the cluster.

In File, click Save.

To launch the Cluster-SOA Debugger and follow a request end-to-end

Press F5 to launch the debugger.

When prompted, type your password to connect to the cluster, and then click OK.

A Command Prompt window appears, and the application pauses at the first breakpoint in the statement to create the session.

Press F10 (Step Over) to step through the code.

If prompted, type your password in the Command Prompt window.

Continue pressing F10 until you reach the following line of code:

client.BeginGetData(i, CallBack, client);

Press F11 (Step Into) to follow the request.

Note

Because this is an asynchronous operation, the debugger may not step immediately into the service process. You can press F5 (Continue) to continue to the breakpoint in the service.

The application stops at the breakpoint in the GetData method in the service code.

Press F11 again to follow the request to the CallBack function in the client code.