Service function is not calling I am trying to validate a key, which I am passing as url argument using service. But service function is not calling.

It's giving "Access denied" error. Am I missing something?

My sample code is:

cunn.routing.yml

cunnotification.saverecord:
  path: '/cunnotification/saverecord/{key}'
  defaults:
    _controller: '\Drupal\cunnotification\Controller\SaveRecordToDBController::SaveRecord'
  options:
    no_cache: TRUE
  requirements:
    _access_cunn_saverecord: 'TRUE'


cunn.services.yml

services:
  cunn.saverecord:
    class: Drupal\cunnotification\Access\CUNAccessCheck
    tags:
      - { name: cunn_access_check, applies_to: _access_cunn_saverecord }


CUNAccessCheck.php

namespace Drupal\cunn\Access;

use Drupal\Core\Routing\Access\AccessInterface;
use Drupal\Core\Access\AccessResult;

/**
 * Access check for conn routes.
 */
class CUNAccessCheck implements AccessInterface {

  /**
   * Checks access.
   *
   * @param string $key
   *   The conn key.
   *
   * @return \Drupal\Core\Access\AccessResultInterface
   *   The access result.
   */
  public function access($key) {
   // Logic here
   return TRUE; // based on logic
  }
}
Don't change they tag name, just access_check:

services:
  cunn.saverecord:
    class: Drupal\cunnotification\Access\CUNAccessCheck
    tags:
      - { name: access_check, applies_to: _access_cunn_saverecord }