Microsoft 9GD00001 Computer Accessories User Manual


 
334 Microsoft Visual Studio 2010: A Beginner’s Guide
This example shows that the proxy will translate the results into a List<Customer>
(List(Of Customer) in VB). While I showed you how to make this setting after creating
the Web service, I chose this sequence because it shows the value of changing the
collection return type. However, you can make this setting when first creating the Web
reference. Looking at Figure 11-11, you can see an Advanced button at the bottom of the
Add Service Reference window. Clicking the Advanced button will show you the Service
Reference Settings window, shown in Figure 11-13, allowing you to set the collection
return type when first creating the service reference.
Now, you’ve seen all five operations of the Web service. Remember that exactly
the same techniques are used here as in any other type of .NET application. For your
convenience, Listing 11-7 shows you the entire example for using a Web service.
Listing 11-7 An application using a Web service
C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CustomerConsole.CustomerService;
namespace CustomerConsole
{
class Program
{
static void Main()
{
var svc = new CustomerServiceClient();
var newCust = new Customer
{
Age = 36,
Birthday = new DateTime(1974, 8, 22),
Income = 56000m,
Name = "Venus"
};
var newCustID = svc.InsertCustomer(newCust);
Console.WriteLine("New Customer ID: " + newCustID);
Customer cust = svc.GetCustomer(newCustID);