Chapter 11: Deploying Web Services with WCF 329

Now that you have a service reference, you can use it in any .NET application. The
following section shows you how to write code to communicate with the Web service.
Coding Web Service Calls
This section will explain how to write code that communicates with a Web service. You’ll
see explanations of the individual statements required to call the Web service and then
you’ll see the entire listing of all of those statements together. The program that calls
the Web service is a Console application. You should create a new Console application
and add the code in this section inside of the Main method. If you felt like skipping
ahead before reading the explanation, you can see the entire code listing of the Console
application that calls the Web service in Listing 11-7. However, we’ll begin at the first
statement and follow until you see all of the code that’s required to call and interact with
the CustomerService Web service created in the preceding sections.
When creating a service reference, as explained in the preceding section, VS will
generate a new class, called a proxy. The proxy looks just like your Web service class
but doesn’t contain any of the same code. Instead, the proxy will translate calls from
the client and communicate with the Web service. The proxy, created after adding the
service reference in the preceding section, is named CustomerServiceClient. Remember
to add a using statement (Imports in VB) for the Web service proxy. Since the default
Figure 11-12 A new service reference in a project