'How to reference a web service with a login form?

I have a username and password in an existing web service, and I want to use the username and password that I have in a method called Login().

I have the followings records:

APIApp.cs

namespace App.Work.API
{
    public class APIApp : IAPIApp
    {
               
        private readonly LogInServiceClient _loginService;
    
        public APIApp()
        {
            String url = @"http://(An IP)";
            BasicHttpBinding binding = new BasicHttpBinding();
           
            this._loginService = new LogInServiceClient(binding, new EndpointAddress(url + "/Services/LogInService.svc"));
    
        }

        // Invocando Login

        public void Login()
        {            
            using (OperationContextScope scope = new OperationContextScope(_loginService.InnerChannel))
            {
                // Pasar los parametros por cabecera.
                // Setting the headers
                 var request  = new HttpRequestMessageProperty();              
              
                request .Headers["Language"] = Language;
                request .Headers["ModuleId"] = ModuleId.ToString(CultureInfo.CurrentCulture);
                            
                OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = request ;
               
                LogInInfoDTO loginInfo = _loginService.AreUserAndPasswordCorrect("(An username)", "(A password)", Extension);

                if (loginInfo.Authenticated)
                {

                (I don't know if I must to put anything there.)

                   
                   
                }

            }
        }

}

}

IAPIApp.cs

namespace APP.Work.API
{
    public interface IAPIResuPlus
    { 
        void Login();
        void ObtenerTrabajadores();
    }
}

A controller:

    using APP.Work.Services.LogInService;
using Microsoft.AspNetCore.Mvc;

namespace APP.Work.View;

[Route("api/[controller]")]
[ApiController]
public class APIAPPController : ControllerBase
{
    IAPIApp _api;
    public APIAPPController(IAPIApp api)
    {
        this._api = api;
    }

    [HttpGet("[action]")]
    public IActionResult Login()
    {
        _api.Login();

        return Ok();
    }

}

The view:

View

I'm sorry if I didn't put the code correctly, but since I'm new to using apis, I'm also new to this forum xD thanks for your help!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source