0
我正在構建一個解決方案,旨在通過WCF代理客戶端使用REST服務,檢索XML數據並將其插入到SQL表中。WCF rest客戶端:由解決方案中的另一個WCF服務觸發時無法發送HTTP消息
我的解決方案有4個項目:
託管一切- 一個控制檯應用程序
- 用於連接到REST服務和XML數據反序列化到對象
- 一類用於解析反序列化對象的一個WCF客戶端類並寫入SQL表格。
- 一個WCF服務類,託管在控制檯中,實現一個引發en事件的操作。
什麼工作正常:
- 實例我的WCF客戶端類,並用它直接從控制檯,
- 實例我的WCF客戶端類,並用它手動觸發我的WCF服務事件 時
什麼不起作用:
- 實例我的WCF客戶端類,當我WCF服務提出了通過HTTP方法調用它的事件=>錯誤提出使用它:文件意外結束
我看了一下詳細的跟蹤記錄,並說發送HTTP消息失敗。
任何線索可能來自哪裏?
這是我的WCF服務的實現:
<ServiceBehavior(InstanceContextMode:=ServiceModel.InstanceContextMode.Single _
, IncludeExceptionDetailInFaults:=True)> _
Public Class RemoteService
Implements IRemoteService
Public Event getGroups As MyHostEventHandler
Public Sub DoWork() Implements IRemoteService.DoWork
RaiseEvent getGroups()
End Sub
End Class
Public Delegate Sub MyHostEventHandler()
這是現在我有我的控制檯應用程序的代碼:
Sub getGroups()
' Instantiate WCF client
Dim proxy As EE2014_DataSolution.EERestAPI = New EE2014_DataSolution.EERestAPI()
' Call WCF REST method getGroups2014()
Dim response_groups As groups = proxy.getGroups2014()
' Instantiate SQL writer class
Dim sql As SqlDataWriter.SqlDataWriter = New SqlDataWriter.SqlDataWriter()
' Pass deserialized object to SQL writter class
Dim numRowsWritten As Integer = sql.WriteGroups(response_groups)
Console.WriteLine(numRowsWritten & " rows updated")
End Sub
Sub Main()
' Instantiate WCF service
Dim host As ServiceHost = New ServiceHost(New RemoteService.RemoteService())
' Handle event (THIS WILL FAIL)
AddHandler CType(host.SingletonInstance, RemoteService.RemoteService).getGroups, AddressOf getGroups
' Start WCF service
host.Open()
Console.WriteLine("RemoteService started at " & Now)
' Wait for WCF messages
Console.WriteLine("Press any key to send HTTP request manually.")
Console.ReadLine()
' Get groups directly from console (THIS WILL WORK)
getGroups()
' Wait for WCF messages
Console.WriteLine("Press any key to send HTTP request manually via event.")
Console.ReadLine()
' Raise the WCF service event manually (THIS WILL WORK)
CType(host.SingletonInstance, RemoteService.RemoteService).DoWork()
' Exit
Console.WriteLine("Press any key to exit.")
Console.ReadLine()
End Sub