To effectively cope with the dynamic and ever-changing web service environment and improve service quality, the optimal web service selection method was studied based on adaptive sticky particle swarm algorithm. An evaluation system was established based on six quantitative indicators and the ordinal relationship analysis method was used to quantify the weights of the indicators. The quality of web services was calculated by combining the weights with the quantified values of the indicators,providing optimization directions for obtaining the optimal service solution. Adaptive mechanisms and viscosity strategies were introduced to enhance the adaptability and global search capability of particle swarm optimization algorithm. Web service quality was used as the fitness function value to evaluate the quality of web service composition solutions and the optimal web service composition solution was found through iterative optimization using adaptive viscous particle swarm algorithm. The results showed that when facing static scenarios,the service quality of the web service composition scheme obtained by the research method remained above 0.9. The average accuracy, recall rate, and F1 score of the web service composition scheme obtained by the research method reached 92.5%, 91.3%, and 91.9 respectively. When facing dynamic scenarios, the service quality remained above 0.8, with the above indicators being 88.7%, 87.6%, and 88.1 respectively, demonstrating excellent adaptability and stability. Therefore, the research method can provide high-quality web service composition solutions in different environments.