【问题标题】:Hosting WCF service in Azure Service Fabric在 Azure Service Fabric 中托管 WCF 服务
【发布时间】:2020-01-05 09:47:37
【问题描述】:

我有一组想要迁移到 Azure Service Fabric 的 WCF 服务。我正在为每个 WCF 服务创建一个服务结构无状态服务,并从我的结构服务中引用 WCF 服务库和合同。我的目标是对现有 WCF 服务库和合同进行零代码更改。结构服务就像包装器一样。

简单服务我成功了,我把WCF服务配置放到fabric服务(.NET框架)的app.config文件中,现有wcf代码中的system.configuration.configurationmanager调用似乎工作正常。

但是,我尝试迁移的许多更复杂的服务包含使用ChannelFactory 调用其他 WCF 服务的代码。我想知道这会起作用吗? Azure Service Fabric 是否允许其服务通过ChannelFactory 进行外部通信调用?

如何读取服务结构中的 WCF 跟踪日志?没有本地驱动器来存储日志文件?

当客户端在结构中调用 wcf 服务时,我也会收到通用连接关闭错误。

[编辑] 负载均衡器已配置,但客户端仍然无法通过:


Could not connect to net.tcp://10.0.0.6:9012/. The connection attempt lasted for a time span of 00:00:21.0433425. TCP error code 10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 10.0.0.6:9012. 
Server stack trace: 
   at System.ServiceModel.Channels.SocketConnectionInitiator.Connect(Uri uri, TimeSpan timeout)
   at System.ServiceModel.Channels.BufferedConnectionInitiator.Connect(Uri uri, TimeSpan timeout)
   at System.ServiceModel.Channels.ConnectionPoolHelper.EstablishConnection(TimeSpan timeout)
   at System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.CallOpenOnce.System.ServiceModel.Channels.ServiceChannel.ICallOnce.Call(ServiceChannel channel, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.CallOnceManager.CallOnce(TimeSpan timeout, CallOnceManager cascade)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
    Inner Exception:
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 10.0.0.6:9012
   at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
   at System.Net.Sockets.Socket.Connect(EndPoint remoteEP)
   at System.ServiceModel.Channels.SocketConnectionInitiator.Connect(Uri uri, TimeSpan timeout)

【问题讨论】:

    标签: wcf azure-service-fabric wcf-binding service-fabric-stateless


    【解决方案1】:

    Azure Service Fabric 是否允许其服务通过 ChannelFactory 进行外部通信调用?

    • Service Fabric 不会阻止您通过网络进行呼叫。请务必在服务清单中声明 endpoint,以便为调用保留端口。

    如何读取服务结构中的 WCF 跟踪日志?没有本地驱动器来存储日志文件?

    • 您在virtual machines 上运行,它有一个数据驱动器和一个临时驱动器。但是,我建议使用存储空间away from the cluster 来保存日志文件,以在集群缩小(例如)时保证它们的安全。

    当客户端在结构中调用 wcf 服务时,我也会收到通用连接关闭错误。

    您是否配置了 Azure Load Balancer 以将流量转发到集群?

    您是否考虑将WCF 服务作为Windows Containers? 运行,这样您可能根本不需要创建SF 服务。

    请注意,WCF 似乎确实not 有一个光明的未来。

    【讨论】:

    • 感谢您的回复!我的每个服务(原始 wcf 的包装器)都绑定到一个特定的端口。我想知道如果我扩展服务会发生什么,会不会有任何端口冲突?
    • 默认情况下,由于 SF 的工作方式,每个节点不会有多个服务实例。但是,如果您运行多个应用程序实例(因此您多次运行相同的服务),则需要在清单中进行管理。
    • 感谢@LoekD,我的一些服务在启动后使用 web api http 自托管。即使每个节点一个实例,我有时也会收到错误:uri 的注册已经存在。好像服务已经启动了几次:stackoverflow.com/questions/57782319/…
    • 服务从一个节点移动到另一个节点可以重新启动。服务关闭时您是否正确关闭了频道? serviceHost.Close()
    • 我无法控制 WCF 服务源代码。服务从 app.config 读取自主机 url。我输入了一些代码来修改这个 url 并附加一个随机的 guid 虚拟目录。我希望这可以避免错误,因为虚拟方向不同,但是,即使使用不同的虚拟目录,我仍然会出错。
    猜你喜欢
    • 2018-09-05
    • 2017-05-14
    • 2011-05-17
    • 2017-04-29
    • 1970-01-01
    • 2012-01-18
    • 2017-06-09
    • 2011-06-22
    • 2019-03-05
    相关资源
    最近更新 更多