added samples
[windows-sources.git] / sdk / samples / WCFSamples / TechnologySamples / Basic / Contract / Data / ObjectReferences / VB / service / service.vb
blobeb65d5c0503a4fc12e27efe8bf587c547c0ae54e
1 ' Copyright (c) Microsoft Corporation. All Rights Reserved.
3 Imports System
4 Imports System.ServiceModel
5 Imports System.Runtime.Serialization
6 Imports System.Collections.Generic
8 Namespace Microsoft.ServiceModel.Samples
10 ' Define a service contract.
11 <ServiceContract([Namespace]:="http://Microsoft.ServiceModel.Samples")> _
12 Public Interface ISocialNetwork
13 <OperationContract()> _
14 Function GetPeopleInNetwork(ByVal p As Person) As List(Of Person)
15 <OperationContract()> _
16 Function GetMutualFriends(ByVal p As Person) As List(Of Person)
17 <OperationContract()> _
18 Function GetCommonFriends(ByVal p As List(Of Person)) As List(Of Person)
19 End Interface
22 <DataContract([IsReference]:=True)> _
23 Public Class Person
24 Private nameField As String
25 Private locationField As String
26 Private genderField As String
27 Private ageField As Integer
28 Private friendsField As List(Of Person)
29 Public Sub New()
30 End Sub
31 <System.Runtime.Serialization.DataMemberAttribute()> _
32 Public Property Age() As Integer
33 Get
34 Return Me.ageField
35 End Get
36 Set(ByVal value As Integer)
37 Me.ageField = value
38 End Set
39 End Property
40 <System.Runtime.Serialization.DataMemberAttribute()> _
41 Public Property Name() As String
42 Get
43 Return Me.nameField
44 End Get
45 Set(ByVal value As String)
46 Me.nameField = value
47 End Set
48 End Property
49 <System.Runtime.Serialization.DataMemberAttribute()> _
50 Public Property Location() As String
51 Get
52 Return Me.locationField
53 End Get
54 Set(ByVal value As String)
55 Me.locationField = value
56 End Set
57 End Property
58 <System.Runtime.Serialization.DataMemberAttribute()> _
59 Public Property Gender() As String
60 Get
61 Return Me.genderField
62 End Get
63 Set(ByVal value As String)
64 Me.genderField = value
65 End Set
66 End Property
67 <System.Runtime.Serialization.DataMemberAttribute()> _
68 Public Property Friends() As List(Of Person)
69 Get
70 If (Me.friendsField Is Nothing) Then
71 Me.friendsField = New List(Of Person)()
72 End If
73 Return Me.friendsField
74 End Get
75 Set(ByVal value As List(Of Person))
76 Me.friendsField = value
77 End Set
78 End Property
80 End Class
83 ' Service class which implements the service contract.
84 Public Class SocialNetworkService
85 Implements ISocialNetwork
86 Public Function GetPeopleInNetwork(ByVal p As Person) As List(Of Person) _
87 Implements ISocialNetwork.GetPeopleInNetwork
88 Dim people As List(Of Person) = New List(Of Person)()
89 ListPeopleInNetwork(p, people)
90 GetPeopleInNetwork = people
91 End Function
93 Public Function GetMutualFriends(ByVal p As Person) As List(Of Person) _
94 Implements ISocialNetwork.GetMutualFriends
95 Dim mutual As List(Of Person) = New List(Of Person)
96 Dim f As Person
97 For Each f In p.Friends
98 If (f.Friends.Contains(p)) Then
99 mutual.Add(f)
100 End If
101 Next
102 GetMutualFriends = mutual
103 End Function
105 Public Function GetCommonFriends(ByVal people As List(Of Person)) As List(Of Person) _
106 Implements ISocialNetwork.GetCommonFriends
107 Dim common As List(Of Person) = New List(Of Person)
108 Dim f As Person
109 For Each f In people.Item(0).Friends
110 If (people.Item(1).Friends.Contains(f)) Then
111 common.Add(f)
112 End If
113 Next
114 GetCommonFriends = common
115 End Function
117 Public Sub ListPeopleInNetwork(ByVal p As Person, ByVal lst As List(Of Person))
118 If (Not lst.Contains(p)) Then
119 lst.Add(p)
120 Dim f As Person
121 For Each f In p.Friends
122 ListPeopleInNetwork(f, lst)
123 Next
124 End If
125 End Sub
126 End Class
129 End Namespace