Chapter 11: Deploying Web Services with WCF

307

<OperationContract()>

Function InsertCustomer(ByVal cust As Customer) As Integer

<OperationContract()>

Sub UpdateCustomer(ByVal cust As Customer)

End Interface

You already know how to specify an interface, and the preceding section explained the purpose of ServiceContract and OperationContract attributes. Listing 11-2 shows that all you need to do is specify the methods that you want to be included as part of the contract.

There are times when you’ll need to return a custom type from a WCF service. For example, if you need to fill in a drop-down list, all you need is a key for the value and a name for the text. So, you can create a custom CustomerLookup class, as shown in Listing 11-3, that specifies DataContract and DataMember attributes. Listing 11-3 demonstrates how a custom type could be coded if you ever needed to do this.

Listing 11-3 A custom type for a WCF service contract

C#:

[DataContract]

public class CustomerLookup

{

[DataMember]

public int CustomerID { get; set; }

[DataMember]

public string CustomerName { get; set; }

}

VB:

<DataContract()>

Public Class CustomerLookup

<DataMember()>

Public Property CustomerID() As Integer

<DataMember()>

Public Property CustomerName() As String

End Class

Page 330
Image 330
Microsoft 9GD00001 manual 307, Listing 11-3 a custom type for a WCF service contract