Exposing Services

This example explains how to service enable the operation on Calc completed in the Standard application example (Using JIA for Standard Applications) and allow 3 parameters to be passed to the function (two integers for the numbers and one string for the operation type). The result is the return value of the method as a string.

The service is invoked and tested using WCF Test Client.

To service enable the Calc operation:

1.In the project code, write the script for automation of the calculation:

    public string Calculate(int num1, int num2, string operation)

    {

        Calc calc = FindWindow<Calc>();            

        //Your logic here for deciding which JIA control to click and         //so forth…

        return calc.resultWindow.Text;

    }

2.In the Service.cs interface of the project, decorate the method signature with the following attributes. The attributes are described in the table following the example.

    [OperationContract]

    [STAOperationBehavior]

    [WebInvoke (ResponseFormat = WebMessageFormat.Json, BodyStyle =     WebMessageBodyStyle.Wrapped)]

    string Calculate(int num1, int num2, string operation);

Attribute

Description/Notes

[Operation Contract]

Exposes the method through the WCF service upon JIA launch.

[STAOperationBehavior]

Ensures that the method is executed on an automation thread. This attribute is especially relevant to Web applications.

[WebInvoke]

Defines how values are returned from the method. In the example above, responses are returned and formatted as .json.

This attribute is read when using the WebBind attribute.

3.Launch JIA, and verify that the JIA project is configured to the BasicHttp binding type:

a. From the File menu, select Configuration.

b. Select the Service Hosting tab.

c. Under Binding Type, select BasicHttp.

d. If prompted, restart JIA.

Note: If the JIA project is not configured to the BasicHttp binding type, WCF Test Client will not be able to call the service.

4.Launch WCF Test Client.

WCF Test Client is part of Visual Studio, and generally is invoked by starting the WcfTestClient.exe, which is located in the Visual Studio installation directory.

5.Add the JIA service to WCF Test Client:

a. In WCF Test Client, right-click on My Service Projects, and select Add Service.

  The Add Service window opens.

Add Service Window

b. Copy the service URL from the Service Hosting tab in the JIA configuration panel, and append the project name to the end of the base URL.

c. Paste the edited URL into the edit box on the Add Service window. Then, click OK.

  The project services are loaded and displayed. The Calculate method is exposed, and the different parameters that can be passed with this method are listed.

WCF Test Client

6.Enter some parameters in WCF Test Client, and invoke the operation. Insert a breakpoint inside Calculate to see the different parameters instantiated with the values you provided in WCF Test Client.