Consuming ASMX and WCF Services Sample

To get samples and instructions for installing them, see the following:

  • Click Samples on the Visual Studio Help menu.

    For more information, see Locating Sample Files.

  • The most recent versions and the complete list of samples are available on the Visual Studio 2008 Samples Web site.

  • You can also locate samples on your computer's hard disk. By default, samples and a Readme file are copied to a folder under \Program Files\Visual Studio 9\Samples\. For Visual Studio Express Editions, all samples are located on the Internet.

To run this sample

  • Locate this sample on the MSDN Web site, and then download and open the sample.

  • Press F5.

Demonstrates

This sample contains two samples, MagicEightBallASMX.sln and MagicEightBall.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 MagicEightBallService.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 IMagicEightBallService), 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 MagicEightBallClient applications are also similar. The ASMX sample has a reference to the MagicEightBallSoapClient; the WCF sample references the MagicEightBallServiceClient. 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.