START PREV NEXT

 

Example of Web Forms Client Consumer for the Web Services:

 

This section will go through how a Web Forms client uses the service of Web Service.

 

PROXY Classes and Web References

 

Since SOAP message formats are already known for any Web Service, developers do not need to manipulate the SOAP messages. .NET can create PROXY classes for Web Services thereby each proxy class and method will correspond to the Web service it’s dealing with. The client can just call the Procy object that will do the job of creating and reading the SOAP messages with the Web Service.

 

The steps involved in creating a .NET client for the VisaValidator:

1.      Generate a Proxy for the Web Service

2.      Compile the Proxy as a DLL library

3.      Create a Visual C# - Console Application Project

4.      Develop the Client.cs class file

5.      Build the Project Files

 

Step I:

 

Open up the Visual Studio IDE and create a WEB FORMS project in C#: Create a TextBox for the Card no, one Label for the Result and one Button named “Validate” for calling the WEB service.

 

 

                       

 

 

 

Step II:

 

 

  1. To create the proxy of the Web Service, right click on References and use Add Web References. Type in the URL of our Web Service which is: http://localhost/XMLWebServices/Tutorial/VisaValidotor/Validation.asmx. Click on GO button.

 

 

 NOTE: This URL could be any known Web Service URL that is accessible from the development machine.

 

 

 

 

  1. After the Web Services are found at the URL typed the window will look like this:

 

 

 

 

Step III:

 

1.      Change the name of the service to “ValidatorService” and click on Add Reference. This will create the PROXY local to the project.

 

 

Step IV:

 

1.   Add “using WebFormsClient.ValidatorService;” in the code to access the PROXY object code.

2.      Double Click on the Validate button to get to it’s code:

            private void Button1_Click(object sender, System.EventArgs e)

            {

                  VISAValidator server = new VISAValidator();

                  bool isValidCreditCard = server.validateVISACard("1234567");

 

                  // Print out the value

                  if (isValidCreditCard)

                        Result.Text = "The card is valid";

                  else

                        Result.Text = "The card is invalid";

           

            }

 

 

Build and run the project to see that the FALSE is returned from the Web Service.