[英]WCF rest client: unable to send HTTP message when triggered by another WCF service in the solution
我正在构建一个旨在通过WCF代理客户端使用REST服务,检索XML数据并将其插入SQL表的解决方案。
我的解决方案有4个项目:
什么工作正常 :
什么不起作用 :
我查看了详细的跟踪日志,它说发送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
我发现了问题的根源:“客户端” WCF方法的上下文被WCF服务的上下文覆盖。 确实,由于进行了诊断程序配置,我注意到我的应用程序尝试发送POST消息而不是GET消息,这使我进入了以下链接,该链接位于解决方案所在:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.