大家好

我目前在从 Windows 服务调用 WCF 服务时遇到问题。我的应用程序解决方案如下所示。

  • Web 管理控制台(Web 项目)
  • 中央控制(Windows服务)
    • WCF 服务,以便 Web 管理控制台可以连接到它并对其进行配置
    • 在节点上使用WCF的几次调用(窗口服务)
  • 节点(Windows 服务)
    • WCF服务允许中央控制Windows服务对其进行配置

Web 管理控制台可以访问中央控制 WCF,但中央控制在尝试连接到节点时超时。在测试中,我创建了一个启动器应用程序,它是一个简单的 Windows 窗体项目,它创建每个服务的一个实例,并有几个按钮,这些按钮在每个 Windows 服务中使用 WCF 函数(只是为了查看失败的原因)这个启动器应用程序无法与任何一个 Windows 服务通信。这让我很困惑,因此我将相同的按钮添加到 Web 管理控制台中的 Web 表单中,并通过 WCF 完美连接到两个 Windows 服务。我知道 WCF 的东西正在工作,因为我可以通过 IE 访问它并看到所有精彩的 XML(显然,从 Web 应用程序进行调用的事实很好地表明它正在启动并运行)

简而言之 我的 Web 应用程序可以使用 Windows 服务中的 WCF 服务,但 Windows 窗体和 Windows 服务不能。为什么是这样!?

我在这个项目上几乎已经没有时间了,所以快速回复就太棒了!

技术/代码详细信息我没有在应用程序中使用配置文件。一切都是通过代码创建的,我一直在使用相同的代码在任何地方进行 WCF 调用。此外,我还尝试关闭所有地方的安全功能,以防出现问题。我也在用同样的 svcutil 还在各处生成代理文件以保持一致

调用 Node 的示例

Dim Bind As New WSHttpBinding(SecurityMode.None, True)
Bind.CloseTimeout = New TimeSpan(0, 0, 10)
Bind.OpenTimeout = New TimeSpan(0, 0, 10)
Bind.SendTimeout = New TimeSpan(0, 0, 10)
Dim client As New BN.BNodeServiceClient(Bind, New EndpointAddress("http://localhost:27374/Node"))
client.sendMessage("Test Message")
client.Close()

节点打开其 WCF

BNodeHost = New ServiceHost(GetType(iBNodeService))
BNodeHost.AddServiceEndpoint(GetType(BNodeService), New WSHttpBinding(SecurityMode.None, True), New Uri("http://localhost:27374/Node"))
Dim metadataBehavior As ServiceModel.Description.ServiceMetadataBehavior
metadataBehavior = BNodeHost.Description.Behaviors.Find(Of _
ServiceModel.Description.ServiceMetadataBehavior)()

If metadataBehavior Is Nothing Then
    metadataBehavior = New ServiceModel.Description.ServiceMetadataBehavior()
    metadataBehavior.HttpGetEnabled = True
    metadataBehavior.HttpGetUrl = New Uri("http://localhost:27374/Node")
    BNodeHost.Description.Behaviors.Add(metadataBehavior)
Else
    BNodeHost.Description.Behaviors.Add(metadataBehavior)
End If

BNodeHost.Open()

在我将不同的部分设置为适当的 Windows 服务并尝试向其添加安装程序之前,这一切都正常工作。安装程序工作正常并安装启动的服务,并允许我在 IE 中查看所有 WCF XML。

正如您可能知道的那样,我对 WCF 非常陌生,这是我使用它的第一个应用程序。基本部分几乎是来自不使用配置文件的示例的复制/粘贴/更改作业。

任何帮助将不胜感激。

有帮助吗?

解决方案

验证 appconfig 中的所有端点是否与管理 web 应用程序的 webconfig 中的设置匹配。每个设置不同的超时值,即:

<system.serviceModel>
        <bindings>
            <wsHttpBinding>
                <binding name="WSHttpBinding_ILookupService" closeTimeout="00:01:00"
                 openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                 bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                 maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text"
                 textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                     maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <reliableSession ordered="true" inactivityTimeout="00:10:00"
                     enabled="false" />
                    <security mode="Message">
                        <transport clientCredentialType="Windows" proxyCredentialType="None"
                         realm="" />
                        <message clientCredentialType="Windows" negotiateServiceCredential="true"
                         algorithmSuite="Default" establishSecurityContext="true" />
                    </security>
                </binding>
            </wsHttpBinding>
        </bindings>
        <behaviors>
            <endpointBehaviors>
                <behavior name="LargeEndpointBehavior">
                    <dataContractSerializer  ignoreExtensionDataObject="true" maxItemsInObjectGraph="2147483647"/>
                </behavior>
            </endpointBehaviors>
        </behaviors>

        <client>
            <endpoint address="http://localhost:59599/LookupService.svc"
             binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_ILookupService"
             contract="FEEALookupServiceReference.ILookupService" name="WSHttpBinding_ILookupService">
                <identity>
                    <dns value="localhost" />
                </identity>
            </endpoint>
        </client>
    </system.serviceModel>

希望有帮助。祝你好运。

其他提示

我无法正确地解决这个问题。Windows 服务与 Windows 服务之间的通信似乎存在问题。有一种方法可以让它在某个地方发生,但我没时间了,所以我通过将其中一个位(中央控制)转换为普通的 Windows 应用程序并以这种方式安装来解决它。效果很好,客户很满意:)

检查运行 Windows 服务的用户的权限 - 他们喜欢默认为网络服务,但可能没有足够的权限。以具有正确权限的专用用户身份运行它们。

并检查 Windows 防火墙。它喜欢阻止您的一些网络连接。我通常只是将其关闭。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top