Search Results for

    Show / Hide Table of Contents

    Invoking HTTP Endpoints

    In distributed architectures, services often need to communicate with one another. Writing service clients manually can be time-consuming, error-prone, and inconsistent. A Service Proxy simplifies this process by allowing developers to reference already defined services in other Intent Architect applications and automatically generate strongly typed clients that adhere to the specified service contract.

    The generated Service Proxy acts as an intermediary between an application and an external service, providing a strongly typed API that abstracts away the complexity of request configuration and client setup.

    This article explains how to model Perform Invocation relationships which are then realized in generated code as Service Proxies which will use HTTP to communicate with target endpoints.

    Note

    Historically, Modeling Service Proxies was required to invoke HTTP Endpoints, although that method is still fully supported, going forward the approach of using Perform Invocation as described in this article is recommended.

    This article will describe the process of creating a Service Proxy from an example eShop.Invoicing application to an eShop.Customers application in the following solution:

    Intent Architect Solution Explorer showing the two applications

    The Services designer for the eShop.Customers application has the following CQRS requests modeled:

    Screenshot of the Services designer in the eShop.Customers application

    Adding the Customer CQRS requests to a diagram

    We will start by adding the CQRS requests from the eShop.Customers applications onto a diagram in the eShop.Invoicing application's Services designer.

    In the Services designer of the eShop.Invoicing application:

    • Add a package reference to the eShop.Customers.Services.

      Package references manager screen showing the packages which need to be selected

      This will make the CQRS requests from the referenced package available for use in our designer.

    • Right-click the package on the designer and select the New Folder option:

      New Folder context menu option on a package

    • Give the folder a name, such as Customers.

    • Right-click the folder and select the New Diagram option:

      New Diagram context menu option on a folder

    • Give the diagram a name such as Customers.

    • Right-click the background of the diagram and select the Add to Diagram option:

      Add to Diagram context menu option

    • You can filter by Customer and then select all the Commands and Queries and then press DONE:

      Items selected to be added to the diagram

      Items added to the Diagram

    Creating a request and have it invoke a CQRS request over HTTP

    • Right-click the diagram and choose the New Query option:

      New Command context menu option

    • Give the Command a name such as GetCustomerByIdCommand.

    • Right-click the Command and select the Invoke Service option:

      Invoke Service context menu option

    • Click the GetCustomersByIdQuery to set it as the Target End.

      Invoke Service association with target end set

    • Right-click the association line and select the Map Call Operation option:

      Map Call Operation context menu option

    • Double click the GetCustomerByIdQuery element in the right-pane to map the command from the left-pane to it:

      Mapping created between GetCustomerByIdCommand and GetCustomerByIdQuery

    • Right-click the CommandCustomerByIdCommand in the left pane and select the Add Property option:

      Add Property context menu option

    • Give it a name of Id and type of Guid:

      The new property given a name and type

    • You can now double click the Id: guid in the right-pane to specify that its field needs to be populated from the Id on the command in the left pane:

      Mapping created between the Id properties

    • Press DONE.

    Run the Software Factory

    Run the Software Factory and review the proposed changes:

    Proposed software factory changes

    Reviewing the changes, observe the following in particular:

    • ICustomersService is being is being created and registered up in HttpClientConfiguration against the also created CustomersServiceHttpClient.
    • Other related contract files such as the Command and its referenced DTOs are being created.
    • The GetCustomerByIdCommandHandler has an implementation as follows:
    public class GetCustomerByIdCommandHandler : IRequestHandler<GetCustomerByIdCommand>
    {
        private readonly ICustomersService _customersService;
    
        [IntentManaged(Mode.Merge)]
        public GetCustomerByIdCommandHandler(ICustomersService customersService)
        {
            _customersService = customersService;
        }
    
        [IntentManaged(Mode.Fully, Body = Mode.Fully)]
        public async Task Handle(GetCustomerByIdCommand request, CancellationToken cancellationToken)
        {
            var result = await _customersService.GetCustomerByIdAsync(new GetCustomerByIdQuery
            {
                Id = request.Id
            }, cancellationToken);
        }
    }
    

    Invoking Service Operations

    The procedure for invoking traditional Service Operations is essentially the same as the above where Invoke Service associations are created with service operations as their target end:

    Screenshot of diagram showing Invoke Service association to the operation of a traditional service

    Mapping configuration for invoking a traditional service operation

    Summary

    This article guided you through using the Invoke Service association to invoke HTTP endpoints.

    Next steps

    You can try invoking other endpoints in the same way as described above.

    • Edit this page
    ☀
    ☾
    In this article
    Back to top Copyright © 2017-, Intent Software Pte Ltd.