Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top