Chapter 11: Deploying Web Services with WCF

331

.Name = "Venus" End With

Dim newCustID As Integer

newCustID = svc.InsertCustomer(newCust)

At this point, you might be wondering where the Customer type came from. As you may recall from the previous section of the chapter that discussed custom objects, the Customer type is a proxy type for the Customer that was defined in LINQ to SQL. Since we set the Serialization Mode of the LINQ to SQL entity model to Unidirectional, the Web service was able to pass the definition of the Customer with the Web service interface, resulting in a Customer proxy.

To perform the insert operation, use the service proxy reference, svc, to pass the instance of the Customer proxy. The following example shows how to get a specified customer from the Web service:

C#:

Customer cust = svc.GetCustomer(newCustID);

VB:

Dim cust As New Customer

cust = svc.GetCustomer(newCustID)

Here, the service proxy reference is used to call GetCustomer with an ID of the requested customer, returning an instance of the Customer proxy. The next example shows how to update a Customer instance:

C#:

cust.Income = 49000m;

svc.UpdateCustomer(cust);

VB:

cust.Income = 49000

svc.UpdateCustomer(cust)

The cust reference in this example is the same reference that was created previously. In this example, we are only changing the Income property. Next, we use the service proxy to call the UpdateCustomer method, passing the Customer proxy reference. If you

Page 354
Image 354
Microsoft 9GD00001 manual 331