そのため、クライアントアプリケーションとWCFサービスをIISサーバーに公開しています。クライアントにWCFサービスをサブスクライブさせ、いずれかのクライアントでボタンがクリックされた後、クライアントアプリの各インスタンスにメッセージをプッシュすることに成功しました。今の私の目標は、WCFアプリケーションからメッセージをプッシュすることですが、WebブラウザーのRESTを介して、Androidでこのインターフェイスを使用し、AndroidクライアントとWindowsクライアントアプリケーションの間で対話できるようにします。誰かが私が何をする必要があるか考えていますか?これが私が働いているインターフェースの基本です。
IService.vb:
<ServiceContract(SessionMode:=SessionMode.Required, CallbackContract:=GetType(IServiceCallback))>
Public Interface IService
<OperationContract(IsOneWay:=True)>
Sub GetClientCount()
<OperationContract(IsOneWay:=True)>
Sub RegisterClient(ByVal id As Guid)
<OperationContract(IsOneWay:=True)>
Sub UnRegisterClient(ByVal id As Guid)
End Interface
Public Interface IServiceCallback
<OperationContract(IsOneWay:=True)>
Sub SendCount(ByVal count As Int32)
End Interface
Service.svc.vb
<ServiceBehavior(InstanceContextMode:=InstanceContextMode.Single, ConcurrencyMode:=ConcurrencyMode.Multiple)>
Public Class Service
Implements IService, IRestService
Private clients As New Dictionary(Of Client, IServiceCallback)()
Private locker As New Object()
Public ReadOnly Property Callback As IServiceCallback
Get
Return OperationContext.Current.GetCallbackChannel(Of IServiceCallback)()
End Get
End Property
'called by clients to get count
Public Sub GetClientCount() Implements IService.GetClientCount
Dim query = ( _
From c In clients _
Select c.Value).ToList()
Dim action As Action(Of IServiceCallback) = Function(Callback) GetCount(Callback)
query.ForEach(action)
End Sub
Private Function GetCount(ByVal callback As IServiceCallback) As Int32
callback.SendCount(clients.Count)
Return Nothing
End Function
'---add a newly connected client to the dictionary---
Public Sub RegisterClient(ByVal guid As Guid) Implements IService.RegisterClient
'---prevent multiple clients adding at the same time---
SyncLock locker
clients.Add(New Client With {.id = guid}, Callback)
End SyncLock
End Sub
'---unregister a client by removing its GUID from
' dictionary---
Public Sub UnRegisterClient(ByVal guid As Guid) Implements IService.UnRegisterClient
Dim query = From c In clients.Keys _
Where c.id = guid _
Select c
clients.Remove(query.First())
End Sub
End Class