我有一個WCF Web服務訪問另一臺計算機上的WCF Windows服務。 Windows服務執行所有數據訪問並將結果傳遞給Web服務。我已閱讀了幾篇關於正確處理WCF服務的服務客戶端的文章,但我不確定在Web服務中執行此操作的最佳方式是什麼。 (如果這會有所幫助,Web服務是PerCall不PerSession)在WCF Web服務內部處理WCF Windows服務客戶端
這是我現在在做:
Public Class Service1
Implements IService1
Private p_oWindowsService As DataService.Service1Client
Public Sub New()
p_oWindowsService = New DataService.Service1Client
End Sub
Public Function GetData(ByVal value As Integer) As String Implements IService1.GetData
Return p_oWindowsService.GetData(value)
End Function
Public Function GetDataUsingDataContract(ByVal composite As CompositeType) As CompositeType Implements IService1.GetDataUsingDataContract
If composite Is Nothing Then
Throw New ArgumentNullException("composite")
End If
If composite.BoolValue Then
composite.StringValue &= "Suffix"
End If
Return composite
End Function
我不處置服務客戶端在現在好了,從我已經讀過這是一個重大問題。我在看的解決方法是這樣的事情的GetData函數內部:
Public Function GetData(ByVal value As Integer) As String Implements IService1.GetData
Using oWindowsService As New DataService.Service1Client
Return oWindowsService.GetData(value)
End Using
End Function
基於關閉What is the best workaround for the WCF client `using` block issue?,我知道我不應該實際上取決於使用塊。但是,我應該在每個功能中創建和部署服務客戶端嗎?這是我真正的問題。
謝謝。
你建議創建和關閉一個服務客戶端一樣這個web服務在每個函數中調用windows服務? – cjw
@cjw請參閱編輯答案。 – CodingYoshi