IoT infrastructures and web services have primarily been deployed in sustainable smart cities and societies. Users are highly attracted to the personalized web services by the IoT infrastructure due to the improved quality of service (QoS) it offers. To acquire service personalization, the complex distribution systems (smart cities) collect users' sensitive data leading to different privacy issues such as unauthorized user access. The heavy security schemes designed for complex architectures cannot be directly implemented in resource‐constrained IoT devices. The existing models designed cannot offer customization to user privacy where the user has little or no control over their data. However, there are other issues in such a system, including centralization, security, privacy, scalability, and communication latency. To overcome these issues, in this paper, we proposed a web service‐based adaptive optimal lightweight CNN (AOLCNN) for a secure smart city. The use of a lightweight convolutional neural network (LCNN) combined with the mayfly optimization (MO) method improves the production process in the smart industry. The MO algorithm not only optimizes the LCNN weights but also enhances the model's performance by selecting the appropriate web service parameters for the user to get rid of irrelevant web services, resulting in increased smart industrial productivity. Blockchain technology is incorporated to enhance the security, privacy, and transparency of IoT systems and also help them to create and verify web services. The built‐in key store system particularly intended for Android smartphones is used in the proposed security‐based web service application. The NIST Curve P‐256 is used to generate key pairs and verify them using the elliptic curve digital signature algorithm (ECDSA). The performance evaluation of the smart web service‐based AOLCNN model in terms of security, privacy, latency, and memory usage shows our proposed model offers significant performance when compared to the conventional techniques. The experimental findings suggest that the AOLCNN satisfies the needs of scalable IoT applications and the security scheme incorporated also helps the device to safeguard it from malicious entities and unauthorized user access. To propose a novel adaptive optimal lightweight convolutional neural network (AOLCNN) based IoT sustainable smart city environment. A software‐designed network (SDN) controller is responsible for manageability, stability as well as observability thereby providing a programming interface to the network infrastructure. The proposed security‐based web service application makes use of an Android‐specific key store system that employs the elliptic curve digital signature algorithm (ECDSA). The security application described in this paper prevents an attacker from obtaining the key and using it to access the web service application.