Scenario: How to Import and Use Web Services in your CA Plex Application

Introduction

Product: CA Plex

Release: 7.1

This scenario describes how as a CA Plex Developer, you can import and use Web services in your CA Plex application model.

This Knowledge Base Article constitutes a portion of the official CA product documentation for this CA product. This Knowledge Base Article is subject to the following notices, terms and conditions.

How to Import and Use Web Services in CA Plex

As a CA Plex Developer, you can import and use Web Services in your CA Plex application models.

The following diagram illustrates how you can import and call Web Services from your application:

Prerequisites

You must have the following prerequisites that are installed to import and use Web Services in the CA Plex application model:

Run the Web Service

This example uses a custom Stock Price web service, which you will build and deploy using Visual Studio 2010.

Running the Stock Quote Web Service

Follow these steps:

  1. Start Visual Studio 2010 and select File, Open, Web Site and type the full location to the StockQuoteWebService folder under the samples directory.

    Note: The relative path for this folder from the samples directory is \Samples\Web Service Import\StockQuoteWebService.

    Running the Web Service

    Note: This web service is simple to import and offers the following defined web method:

    public double GetQuote(string symbol)

    This web service takes a stock symbol that is passed as a string, and uses the Yahoo! Stock Quote CSV API to return quote data for that symbol. The web service then parses this data and returns the last available traded stock price for that symbol as a numeric double.

  2. Select Debug, Start Debugging to run the web service.

    The ASP.NET Development Server starts and hosts the web service. The Service.asmx page opens in a browser displaying the available web service operations on the running service.

    Important! Ensure to note the Service.asmx page URL path, which you require for the WSDL to run the web service.

    Example: The Service.asmx page URL in this example is http://localhost:60999/StockQuoteWebService/Service.asmx, however, this URL path may differ on your machine. The path differs because the port used by the ASP.NET development server that hosts the web service allocates the port number at runtime.

    Running Web Service

  3. Click the GetQuote hyperlink to test calling that operation.

    The list of input parameters that are required for the call displays. In this example, the symbol you want to get the quote for displays.

    Running the Web Service

  4. Type a valid symbol and click Invoke to call the web service.

    The SOAP response message displays the output from the call and the web service starts running on your machine.

    Web Services

Import the Web Service into Your CA Plex Local Model

After you start the web service to run on your machine, import the same into your CA Plex local model.

Follow these steps:

  1. Open the local model WebServiceImportSample.mdl.

    This local model is initially blank, but has the FOUNDATION and all other dependent libraries attached.

  2. Select Tools, Import, Web Service Import.

    The CA Plex Web Service Import Tool dialog opens.

  3. Type the web service address that you started to run and click Go to start the web service discovery process.

    Note: Since, the service is an ASP.NET based web service, navigating to this address returns the WSDL associated with the web service.

    After the web service returns the WSDL, the CA Plex Web Service Import Tool parses the web service description that is returned, and lists the details on the web service in the tree hierarchy on the left-hand side of the dialog.

    If you select any part of the WSDL containing the HTML documentation, then the documentation displays in the browser pane on the right-hand side of the dialog.

  4. Select the GetQuote operation and notice how the description matches with what you see in your browser.

    Import Web Service

  5. When you add the web service to your local model, it imports as a Package object with a series of scoped objects that describe the various parts of the web service.
  6. Type StockQuoteWebServiceRef as the package name that you are importing into your CA Plex local model, and click OK to import the web service.

    A message prompts that 65 objects have been displayed into your local model.

  7. Click OK.

    The CA Plex Web Service Import Tool dialog closes and your CA Plex local model opens.

  8. After you import the web service, focus the Plex Object Browser on objects of type Package, and click Refresh or (F5).

    Review the objects, which were created from the web service WSDL document.

    Import Web Service

    The following table explains the relationship between the WSDL document objects and the CA Plex objects created that represent them.

WSDL 2.0 Object

Plex Object

Example

Comments

Service

Package

StockQuoteWebServiceRef

The top-level container, which describes the grouping of functions exposed on the web service.

Endpoint

 

 

The endpoint defines the address where the web service is located. This is stored in the narrative for the Package object in Plex.

Interface

Component

StockQuoteWebService

The WSDL interface defines a group of operations, which the web service exposes. Because there is not the concept of components which contain multiple interfaces in WSDL, each interface is represented as a component object in Plex.

Operation

Function

GetQuote

An operation defines one discrete unit of functionality which may be called against the web service. This is the object that Plex developers will want to invoke via action diagram Call statements.

Types

Field

GetQuoteReturn

symbol

The types describe the data passed to and from an operation. These can be thought of as the input and output parameters of a traditional function call.

When you review the triples that are associated with the imported web service Package, Component, Function, and Field objects, you can see some other important information about them.

Note: There will never be any dual or output fields against web service operations imported into Plex; the SOAP request always maps to input parameters and the SOAP response always maps to the return value against the call.

Import WS-3

Workaround:

To use the System.Value.Double and System.Value.String values in C# panel functions, add the following two triples to your model to define the fields:

System.Value.Double decimal places NBR 2

System.Value.String length NBR 12

Save your model before continuing. You have now successfully imported the web service into your Plex local model.

Call a Web Service Operation from an Action Diagram

After you imported the web service into your CA Plex local model, call the web service from your action diagram code.

Creating a simple UI enables you to set the symbol to retrieve the stock price for and display the returned share price as output from the call.

Follow these steps:

  1. Type the following triples in the Plex Model Editor, to create a simple function that contains the panel and has a local variable defined.

    Call WS - 1

  2. Edit the TestStockQuote.Panel panel by dragging the two fields that are scoped to the GetQuote function and dropping them onto the panel design surface. When prompted, add the three fields to the InputP single instance region on the panel.

    Call WS - 2

  3. Add a button to the UI to call the web service operation.
  4. Name the Get Quote button and map it to a logical event called GetQuote.

    Call WS - 3

  5. Save and close the Panel design.
  6. Edit the action diagram for the TestStockQuote function.
  7. To call the web service operation within the action diagram, reference the web service component from the action diagram using the Object Reference Field, a special type of field.

    Note: You can create object reference fields manually in your model, by creating field and adding FldReferenceCom and FldTypeSys/Object triples. However, you can also create object reference fields automatically by dragging the Component, which represents the web service into a local variable in the AD Variable Palette.

    Cass WS - 4

    A dialog prompts you to enter some details on the object reference field that you intend to create.

  8. Type StockQuoteRef as name in the Select Reference Field dialog and click OK.

    WebServices-Part3-step6

    A new object reference field is created and added to the Local variable that is used by the function.

    If you drill down into the object reference field, you can see the GetQuote service operation is now visible within the action diagram.

    Call a Web Service

  9. Call this web service operation as you call any other Function object within Plex, so that you can perform the following tasks:
  10. Add the following AD code to the Pre Point Events to perform the following tasks:

    Call a Web Service

  11. Save and close the action diagram.

Generate, Build, and Run a Web Service-enabled CA Plex .NET Application

After you call the web service from an action diagram, you must now generate, build, and run your CA Plex application, which uses a web service.

Follow these steps:

  1. Open the Generate and Build window.

    The two objects to generate appear:

  2. Generate and build both the objects.
  3. Create an .Exe for the TestStockQuote function.

    Note: This step is required only for CA Plex r7.0. For CA Plex r7.1, you can use the new Generic Bootstrap Executable for .NET to run the function from the generate and build window without creating an .Exe.

  4. Run the TestStockQuote function from the Plex generate and build window.
  5. Type a stock symbol and click Get Quote.

    Generate, Build, and Run

    The CA Plex application calls the web service, which returns the stock quote back to the application to be displayed on the panel.

Troubleshooting

Use the following information to help you troubleshoot the usual errors that you might encounter during importing and calling a web service.

An Exception from the Running Web Service

Symptom:

The back-end sample web service is not properly written and there are scenarios where the service operation crashes.

Example:

When you try to supply an empty stock symbol to the service, the web service throws an index out of bounds exception when the Yahoo! Stock Quote API returns an invalid value.

Solution:

In this example, because the error is in the back-end web service, the CA Plex .NET runtime unwinds the exception stack trace and reports the root cause of the error in the Plex Message Log. The following image shows that the root cause was an index out of bounds exception inside the running back-end web service.

Exception in Running a Web Service

Web Service Unavailable

Symptom:

If the Plex .NET Runtime cannot connect to the server, you get a connection error that looks similar to a standard Plex remote call error.

Example:

The StockQuoteWebService is not running under debug mode in the ASP.NET Development Server, and as such, the Plex .NET Runtime cannot call the web service. You get the following connection error message: “No connection could be made because the target machine actively refused it”.

Web Service Unavailable

Solution:

You get this error in one of the following scenarios:

Note: If you have other connectivity issues, such as security or proxy configuration issues, the diagnostic trace message provides more information on the nature of the problem. If the web service address has changed, you can update the address to the WSDL in the Plex local model. The address is stored in the narrative for the Package object that represents the web service.

Copyright

Copyright © 2014 CA. All rights reserved. All trademarks, trade names, service marks, and logos referenced herein belong to their respective companies.

Back to the Top