Consuming ASMX and WCF Services Sample
This sample has two parts. The first part, the PredictorASMX solution, demonstrates how to call an ASMX service (formerly known as an ASP.NET Web Service) from a client application. The second part, the Predictor solution, demonstrates how to call a WCF (Windows Communication Foundation) service from a client application.
To get samples and instructions for installing them
Do one or more of the following:
On the Help menu, click Samples.
The Readme displays information about samples.
Visit the Visual Studio 2008 Samples Web site. The most recent versions of samples are available there.
Locate samples on the computer on which Visual Studio is installed. By default, samples and a Readme file are installed in drive:\Program Files\Microsoft Visual Studio 9.0\Samples\lcid. For Express editions of Visual Studio, all samples are located online.
For more information, see Visual Studio Samples.
This sample code is intended to illustrate a concept, and it shows only the code that is relevant to that concept. It may not meet the security requirements for a specific environment, and it should not be used exactly as shown. We recommend that you add security and error-handling code to make your projects more secure and robust. Microsoft provides this sample code "AS IS" with no warranties.
To run this sample
Locate this sample on the MSDN Web site, and then download and open the sample.
This sample contains two samples, PredictorASMX.sln and Predictor.sln, which demonstrate two different types of services in Visual Basic. Both samples use service to return answers to questions asked by the client application. For best results, open both solutions in separate instances of Visual Basic so that you can compare the two techniques.
In both solutions, the file PredictorService.vb contains the code for the service. Note the attributes at the top of each module. For the ASMX service, WebServiceAttribute and WebServiceBindingAttribute attributes are used to mark the class as an ASMX Web service. The WCF service consists of a ServiceContractAttribute (defined as the interface IPredictorService), a class that implements that service, and entries in the Web.config file that specify behavior associated with that implementation.
If you compare the Web.config files for both solutions you will see that they are similar, except that the WCF version has an additional system.ServiceModel section. This section identifies the endpoint and binding for the service in addition to the behavior of the service.
The two PredictorClient applications are also similar. The ASMX sample has a reference to the PredictorSoapClient; the WCF sample references the PredictorServiceClient. If you compare the App.config files for the two client applications, you will notice that both contain a system.ServiceModel section. The ASMX version uses a basicHttpBinding to connect to the .asmx endpoint; the WCF version uses a wsHttpBinding to connect to the .wcf endpoint.