This page will go through how a client uses the service of Web Service. The client is called consumer that can be any type of application: windows, a server process, another XML Web Service. The only requirement of a consumer is that it should be able to send and request correct format of the messages.
The ASP.NET web services support three types of communications:
· SOAP
· HTTP-GET and
· HTTP-POST
Interface contracts are described using WSDL. Once this WSDL is available at a URL or within a file, a Web Services proxy class can be generated either by directly using the standalone tool WSDL.EXE shipped with the SDK or implicitly when using the Visual Studio .NET 'Add Web Reference' facility:
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:
To generate the proxy, use the wsdl tool from the command prompt which will create the proxy class:
Step II:
1. Create a .NET dll for the proxy class so that any type of .NET project can access it.
Step III:
Create a new .NET project for Console application and add the reference to the dll created:
Step IV:
Change the code to something like this for the calls to Proxy object that will in turn call the web service for validation:
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
// Create a proxy
VISAValidator server = new
VISAValidator();
// Invoke generateOID()
over SOAP and get the new OID
bool
isValidCreditCard = server.validateVISACard("1234567");
// Print out the value
if
(isValidCreditCard)
Console.WriteLine ("The card is
valid\n");
else
Console.WriteLine ("The card is
invalid\n");
}
Build and run the project to see that the FALSE is
returned from the Web Service.