1 ' Copyright (c) Microsoft Corporation. All Rights Reserved.
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
)
22 <DataContract([IsReference
]:=True)> _
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
)
31 <System
.Runtime
.Serialization
.DataMemberAttribute()> _
32 Public Property Age() As Integer
36 Set(ByVal value
As Integer)
40 <System
.Runtime
.Serialization
.DataMemberAttribute()> _
41 Public Property Name() As String
45 Set(ByVal value
As String)
49 <System
.Runtime
.Serialization
.DataMemberAttribute()> _
50 Public Property Location() As String
52 Return Me.locationField
54 Set(ByVal value
As String)
55 Me.locationField
= value
58 <System
.Runtime
.Serialization
.DataMemberAttribute()> _
59 Public Property Gender() As String
63 Set(ByVal value
As String)
64 Me.genderField
= value
67 <System
.Runtime
.Serialization
.DataMemberAttribute()> _
68 Public Property Friends() As List(Of Person
)
70 If (Me.friendsField Is
Nothing) Then
71 Me.friendsField
= New List(Of Person
)()
73 Return Me.friendsField
75 Set(ByVal value
As List(Of Person
))
76 Me.friendsField
= value
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
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
)
97 For Each f
In p
.Friends
98 If (f
.Friends
.Contains(p
)) Then
102 GetMutualFriends
= mutual
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
)
109 For Each f
In people
.Item(0).Friends
110 If (people
.Item(1).Friends
.Contains(f
)) Then
114 GetCommonFriends
= common
117 Public Sub ListPeopleInNetwork(ByVal p
As Person
, ByVal lst
As List(Of Person
))
118 If (Not lst
.Contains(p
)) Then
121 For Each f
In p
.Friends
122 ListPeopleInNetwork(f
, lst
)