Thứ Sáu, 15 tháng 8, 2014

developing web service using JAX-WS

Yêu cầu đề bài : Happy Consumer International Bank (HCIB), a leading multinational organization having established branches all over the world is now starting its banking services in India. The Bank has employed you as a full time System Consultant with them. It wants to deploy a Web Service that will offer credit card validation and online banking facilities that are typically offered by all the multinational banks. The main priorities for the online banking system are reliability, availability and serviceability of the application. Additionally, the system should be highly scalable and secure as the bank expects substantial growth in the
future. Consider yourself to be a part of the team that implements the credit card validation module. Develop a JAX_RPC based Web Service that exposes the boolean validateCreditCard(cardNumber) method. This method implements the logic for credit card number validation, and returns a boolean value indicating whether the card number is valid or not. Logic for credit card number validation:
Step 1: Multiply the alternate digits of the credit card number by 2 starting with the second digit from the right (the first right--hand digit is the check digit.)
Step 2: Add the individual digits comprising the products obtained in Step 1 to each of the unaffected digits in the original number.
Step 3: The sum of all digits obtained after Step 2 as well as unaffected digits must be a number which is a multiple of 10 (30, 40, 50, etc.) for the credit card number to be valid.

Giải quyết vấn đề :  Bài toán yêu cầu viết 1 chương trình có chức năng check credit Card hợp lệ.Đầu tiên ta tạo 1 java web application có chức năng như 1 server : Sau đó ta tạo 1 webservice bằng cách chọn new  > other > Web service > Web service


class web service này ta tạo lớp boolean validate để trả về giá trị đúng hoặc sai dựa theo thuật toán đề bài yêu cầu :


Sau đó ở thư mục web Service ta chọn Test WebService để hiển thị ra cấu hình và thu được kết quả :


Ở đây ta sẽ sử dụng đường dẫn WSDL để kết nối với client.
Tạo 1 java application làm client.Sau đó create 1 web service client trong mục web service như trong hình


Sau đó copy đường dẫn WSDL vừa có vào mục WSDL Url:


Netbean sẽ tự zen code ra cho chúng ta.Mở foder web service references rồi kéo mục creditCardValidator vào class main trong java application vừa tạo .rồi in ra credit card mà ta muốn check :
Ta chạy và thu về được kết quả.
Nếu credit card hợp lệ :
và nếu không :

Không có nhận xét nào:

Đăng nhận xét