332Microsoft Visual Studio 2010: A Beginner’s Guide

wanted to see the changes that were made, you could call the GetCustomer method again, like this:

C#:

Customer updatedCust = svc.GetCustomer(cust.CustomerID);

VB:

Dim updatedCust As Customer

updatedCust = svc.GetCustomer(cust.CustomerID)

Similarly, you can delete a Customer, as follows:

C#:

svc.DeleteCustomer(updatedCust.CustomerID);

VB:

svc.DeleteCustomer(updatedCust.CustomerID)

As in the previous example, we use the service proxy reference to call the DeleteCustomer method, passing in an ID from the updated customer. The updatedCust reference was from the previous call to GetCustomer. If you wanted to get all of the Customer records from the Web service, you could call GetCustomers, like this:

C#:

Customer[] customers = svc.GetCustomers();

VB:

Dim customers As Customer() customers = svc.GetCustomers()

While this is similar to other method calls in previous examples, you might notice that the return value from GetCustomers here is an array of Customer, Customer[] (Customer() in VB). However, the Web service defined GetCustomers as returning a List of Customer, List<Customer> (List(Of Customer) in VB), as specified in the ICustomerService interface in Listing 11-2 and implemented in the CustomerService class in Listing 11-5. As you may recall, the proxy is responsible for translating the XML return value from the Web service into an object, or collection of objects in this case. By default, the proxy translates all collections into an array. However, you can change the return collection type by right-clicking the Service Reference in your project and selecting Configure Service Reference, showing the Service Reference Settings window in Figure 11-13.

Page 355
Image 355
Microsoft 9GD00001 manual Similarly, you can delete a Customer, as follows