1 ' Copyright (c) Microsoft Corporation. All rights reserved.
4 Imports System
.Collections
5 Imports System
.Collections
.Generic
6 Imports System
.ServiceModel
7 Imports System
.ServiceModel
.Web
9 Namespace Microsoft
.ServiceModel
.Samples
.AdvancedWebProgramming
11 <ServiceBehavior(InstanceContextMode
:= InstanceContextMode
.[Single])> _
13 Implements ICustomerCollection
14 Private counter
As Integer = 0
15 Private customers
As New Hashtable()
16 Private writeLock
As New Object()
18 Public Function AddCustomer(ByVal customer
As Customer
) As Customer Implements ICustomerCollection
.AddCustomer
21 Dim match
As UriTemplateMatch
= WebOperationContext
.Current
.IncomingRequest
.UriTemplateMatch
23 Dim template
As New UriTemplate("{id}")
24 customer
.Uri
= template
.BindByPosition(match
.BaseUri
, counter
.ToString())
26 customers(counter
.ToString()) = customer
28 WebOperationContext
.Current
.OutgoingResponse
.SetStatusAsCreated(customer
.Uri
)
34 Public Sub DeleteCustomer(ByVal id
As String) Implements ICustomerCollection
.DeleteCustomer
35 If Not customers
.ContainsKey(id
) Then
36 WebOperationContext
.Current
.OutgoingResponse
.SetStatusAsNotFound()
44 Public Function GetCustomer(ByVal id
As String) As Customer Implements ICustomerCollection
.GetCustomer
45 Dim c
As Customer
= TryCast(Me.customers(id
), Customer
)
48 WebOperationContext
.Current
.OutgoingResponse
.SetStatusAsNotFound()
56 Public Function GetCustomers() As List(Of Customer
) Implements ICustomerCollection
.GetCustomers
57 Dim list
As New List(Of Customer
)()
60 For Each c
As Customer
In Me.customers
.Values
68 Public Function UpdateCustomer(ByVal id
As String, ByVal newCustomer
As Customer
) As Customer Implements ICustomerCollection
.UpdateCustomer
69 If Not customers
.ContainsKey(id
) Then
70 WebOperationContext
.Current
.OutgoingResponse
.SetStatusAsNotFound()
75 customers(id
) = newCustomer