WCF 从 Windows 服务超时,但 Web 应用程序不超时

发布于 2024-07-18 12:19:03 字数 2414 浏览 3 评论 0原文

大家好

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

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

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

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

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

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

调用节点的示例

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 非常陌生,这是我使用它的第一个应用程序。 基本部分几乎是来自不使用配置文件的示例的复制/粘贴/更改作业。

任何帮助将不胜感激。

Hi All

I am currently having an issue calling a WCF service from a windows service. My Application Solution looks like this.

  • Web Administration Console (Web Project)
  • Central Control (Windows Service)
    • WCF service so the Web Administration Console can connect to it and configure it
    • Several Calls to use WCF on the Node (Window Service)
  • Node (Windows Service)
    • WCF service to allow the Central Control Windows service configure it

The Web Administration Console can access the Central Control WCF but the Central Control Times Out when ever it tries to connect to the Node. In testing this I created a Launcher app which is a simple Windows Form Project which creates an instance of each service and has a couple of buttons which use a WCF function in each of the windows services (just to see what was failing) this Launcher app couldn’t speak to either of the Windows Services. This was confused me so I added the same buttons to a Web Form in the Web Administration Console and it connected to both Windows Services perfectly through WCF. I know the WCF stuff is working as I can hit it through IE and see all of the wonderful XML (and obviously the fact that the calls work from the web app are a good indication of it being up and running)

In short
My web apps can use the WCF services in my Windows Services but Windows Forms and Windows services cannot. Why is this!?

I have pretty much already run out of time on this project so speedy replies would be awesome!

Tech/Code details
I am not using config files in the applications. Everything is being created through code and I have been using the same code to make my WCF calls every where. Also I have tried to turn security off everywhere in case that was the issue. Also I am using the same svcutil generated proxy files everywhere as well to keep it all consistent

Example of a call to the 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()

The Node opening its 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()

This was all working before I made the different bits proper Windows Services and tried to add installers to it. The installers work fine and install the services which start and allow me to see all the WCF XML in IE.

As you might be able to tell, I am very new to WCF and this is my first application using it. The fundamental bits have been pretty much Copy/Paste/Alter jobs from a sample that doesn’t use config files.

Any help would be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

下雨或天晴 2024-07-25 12:19:03

验证 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>

希望有帮助。 祝你好运。

verify that all the endpoints in the appconfig match the settings in the admin webapp's webconfig. each one sets various timeout values, ie:

<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>

hope that helps. good luck.

酒儿 2024-07-25 12:19:03

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

I couldn't work this one out properly. There seemed to be an issue with Windows Service to Windows Service communication. There is a way of making it happen somewhere but I ran out of time so I solved it by turning one of the bits (the Central Control) into a normal windows application and installed it that way. Works fine and the client is happy :)

笑红尘 2024-07-25 12:19:03

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

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

Check the permissions for the users that the Windows Services are running under - they like to default to Network Service which may not have sufficient permissions. Run them as a dedicated user with the correct permissions.

And check Windows Firewall. It loves to block some of your web connections. I usually just turn it off.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文