added SSCLI 1.0
[windows-sources.git] / sdk / samples / WCFSamples / TechnologySamples / Basic / Web / AdvancedWebProgramming / VB / Service.vb
blobc57a2605eb5b9932b60fe2c019bab87ccef72ff0
1 ' Copyright (c) Microsoft Corporation. All rights reserved.
3 Imports System
4 Imports System.Collections
5 Imports System.Collections.Generic
6 Imports System.ServiceModel
7 Imports System.ServiceModel.Web
8 Imports System.Text
9 Namespace Microsoft.ServiceModel.Samples.AdvancedWebProgramming
11 <ServiceBehavior(InstanceContextMode := InstanceContextMode.[Single])> _
12 Public Class Service
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
19 SyncLock writeLock
20 counter += 1
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)
29 End SyncLock
31 Return customer
32 End Function
34 Public Sub DeleteCustomer(ByVal id As String) Implements ICustomerCollection.DeleteCustomer
35 If Not customers.ContainsKey(id) Then
36 WebOperationContext.Current.OutgoingResponse.SetStatusAsNotFound()
37 Else
38 SyncLock writeLock
39 customers.Remove(id)
40 End SyncLock
41 End If
42 End Sub
44 Public Function GetCustomer(ByVal id As String) As Customer Implements ICustomerCollection.GetCustomer
45 Dim c As Customer = TryCast(Me.customers(id), Customer)
47 If c Is Nothing Then
48 WebOperationContext.Current.OutgoingResponse.SetStatusAsNotFound()
49 Return Nothing
50 End If
52 Return c
53 End Function
56 Public Function GetCustomers() As List(Of Customer) Implements ICustomerCollection.GetCustomers
57 Dim list As New List(Of Customer)()
59 SyncLock writeLock
60 For Each c As Customer In Me.customers.Values
61 list.Add(c)
62 Next
63 End SyncLock
65 Return list
66 End Function
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()
71 Return Nothing
72 End If
74 SyncLock writeLock
75 customers(id) = newCustomer
76 End SyncLock
78 Return newCustomer
79 End Function
81 End Class
82 End Namespace