Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Can NOT connect to Windows Service with Windows 7

Posted on 2011-04-27
19
Medium Priority
?
1,750 Views
Last Modified: 2012-05-11
I am running a window service that was built with C# in Visual Studio 2005.
Attempts to connect to the Windows Service fail when running on Window 7.

Why is this?  See error messages below....

Operating System Status:
It has worked with Window 7 Ultimate 32 bit (not sure how?), and XP
It has failed with Win7 Pro 32-bit, Windows 7 Ultimate 64 bit, Windows 7 Enterprise 64 bit

The error messages and stack trace can be seen below:

ERROR 1:
Could not connect to net.tcp://localhost:8252/xxxxxxxxxxx/Control.   The connection attempt lasted for a time span of 00:00:01.0135255.  TCP error code 10061: No connection could be made because the target machine actively refused it 127.0.0.1:8252.

ERROR 2:
The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state.

STACK TRACE:
at System.ServiceModel.Channels.SocketConnectionInitiator.Connect(Uri uir, TimeSpan timeout)
at System.ServiceModel.Channels.BufferedConnectionInitiator.Connect(Uri uir, TimeSpan timeout)
at System.ServiceModel.Channels.TracingConnectionInitiator.Connect(Uri uir, TimeSpan timeout)
at System.ServiceModel.Channels.ConnectionPoolHelper.EstiblishConnection(TimeSpan timeout)
at System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.EnsureOpened(TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(…..

EXCEPTION THRWON AT:
At System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage ret Msg)
At System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, int32 type)
.
.

I have seen online posts on this topic that have not solve the issue.  
What else can I try...?

Thanks for your insight ! !
0
Comment
Question by:psft
  • 10
  • 8
19 Comments
 
LVL 5

Expert Comment

by:morgulo
ID: 35479031
I think, TCP port is used by other process. Try connect by telnet to the service. The port could be also blocked by firewall.
0
 
LVL 7

Expert Comment

by:OklahomaDave
ID: 35479459
Be sure to check the status of Windows Firewall. It could very well be blocking the port, and if so, you'lll need to allow an exception for that app and port to allow it through.

The simplest short-term fix is to *temporarily* turn off Windows Firewall completely, then re-attempt connection to your service. If it works, you know that's the problem, and can work on creating the proper rules to allow the connection after turning the firewall on again.

Good luck!
0
 
LVL 1

Author Comment

by:psft
ID: 35484730
As you can see from the attached images I tried the recommendations to the best of my knowledge with no luck yet.  

Here is what I did:

1.      Shut off the windows firewall. (I just stopped the firewall service)  Does this “Stop” the firewall?
a.      When I look at : Control Panel > Windows Firewall > Customize Settings, I am not allowed to shut off the firewall (its grayed out)…  so does stopping the service suffice?

2.      Allowed access to port 8252 in the firewall.  (see attached image)

3.      Tried connecting to telnet…  (How do I determine with telnet if other processes are using the port?)

Thanks for the feedback!


FirewallOff.JPG
PortAllowedOnFirewall.JPG
TelnetMessage.JPG
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 1

Author Comment

by:psft
ID: 35484971
OK,  I have a Laptop that this it is working on and a desktop that it is not.

I ran the telnet command : "telnet localhost 8252" , on each computer.

The laptop gave me a blank black screen (success)

The desktop gave me the message above : "Could not open connection to host . . . "  (failure)

so I just need to figure out why the port is being blocked on the desktop....  any ideas?  what am I missing?  
 
0
 
LVL 7

Expert Comment

by:OklahomaDave
ID: 35485448
I strongly believe your application simply isn't starting.

Try this as a "next step" from a detective point of view.

Once you've started your VB6 service, open up Task Manager and look for the name of your executable in the list. Be sure to set the option to "Show processes from all users."

If you don't see your executable in the list, I think it would be proof your app may be starting, but then terminating shortly thereafter due to some error associated with running the app as a service. That's when you get into the availability of associated DLL's or permissions to paths, etc, and where ProcMon would come in *very* handy.

Looking forward to continue working you through this!

-David
0
 
LVL 1

Author Comment

by:psft
ID: 35486213
Hi David,
I did what you said.

I started the started the service and then checked the 'Processes' in 'Windows Task Manager'.
The .exe is there.  

I am going to check what happens if I kill the firewall on a different laptop and see if it runs... on that one.  Maybe all the security from my desktop is not allowing access to that port for some reason...?  

Any other ideas?  How can I figure out how / why that port is blocked?
Thanks.
0
 
LVL 7

Expert Comment

by:OklahomaDave
ID: 35486429
psft:

For your service, do you have "Allow service to interact with desktop" checked?

The other thing I'm suspecting is that this setting is *not* checked, and something after the application starts is causing the VB runtime to display some sort of error dialog to the null console session - and because there's no way to access that session, the dialog can't be cleared, hence the .exe hangs forever.

Let's think about the other side - it looks like you've set up all the rules to allow connections *to* the service, so now I wonder if your firewall is blocking what amounts to your *outbound* request from Telnet to your app. That's out there, to be sure, but its at least possible.

Here's something else we can try, and you may have already tried it (forgive in advance if you have)

Open up an Administrator command prompt, and type the following:

netstat -a -o | findstr /I "listening" | findstr "8252"

Open in new window


This should return a list of sessions currently llistening on port 8252, along with the PID of the process that's doing the listening. That PID should match that of your process as seen in Task Manager; if it does, you've got all-but conclusive proof your app is listening on the right port and is operating. If you see netstat return something on that port, but the PID *doesn't* match that of your app, then another process is using that port.

If you don't get any entries at all, it would strongly suggest your app, even it its running, isn't listening on the port. If you do see it, then we're back to something blocking one way or the other.

Let me know what you find out...really interested in getting this fixed for you!

-David
0
 
LVL 1

Author Comment

by:psft
ID: 35486706
Nothing was returned from this call:

netstat -a -o | findstr /I "listening" | findstr "8252"
0
 
LVL 1

Author Comment

by:psft
ID: 35486709
Nothing was returned from this call:

netstat -a -o | findstr /I "listening" | findstr "8252"
0
 
LVL 7

Expert Comment

by:OklahomaDave
ID: 35486904
psft,

If that returned no data, and you still see your service .exe in the Task Manager list, then it almost certainly leads me to believe your application has started, experienced an error, and may well be trying to display a dialog as I mentioned in my earlier post.

There exists at least the possibility that any error messages or dialogs the app tries to display could be written to the WIndows event log. VB6 had an option for executables to run with "unattended execution" that prevented those phantom dialogs. If your app was compiled with that switch flipped, you may have event log entries you can examine.

If you can run the application from your desktop, I would set the service to log in *as you* (assuming you have "Log On As A Service" right, which is not a given). Also, just out of curiosity, even if you're running the app from your desktop, I would move it to an installation folder such as ProgramFiles. This is because a folder such as your desktop will not be available to other user identities that you may set up to log on with your service.

We're close to the point of needing to add some logging to the source if at all possible. I haven't tried to run VB6 under Windows 7, not even sure it will, but it should be happy (relatively) under XP.

So, next step, based on the observation that the app is running, but not listening:

1. If you haven't already, move the executable to a location other than your desktop (or any user-specific folder), and reconfigure your service setup accordingly.
2. Check the event log to see if the app may be writing error messages there.
3. Break out the source and add some logging at conspicuous points to determine where the thing is dying (desperate last gasp...not giving up yet, though).

-David
0
 
LVL 7

Expert Comment

by:OklahomaDave
ID: 35486921
One other item: I would also DEFINITELY snag a copy of procmon and have it running as you start that service. I have a feeling you're going to see a file not found or access denied message associated with some dependent DLL...

-David
0
 
LVL 1

Author Comment

by:psft
ID: 35487258
I got the application procmon but it doesn't seem to be working correctly as once I try to run the exe it doesn't do anything. . . .   I'll look at it more

I will see if I can track down any logs or put trace logs in the source to catch more details.   I do have the source.

Also, not that it changes anything.  I am using C# with Visual Studio .Net 2005, not Visual Basic
0
 
LVL 7

Expert Comment

by:OklahomaDave
ID: 35487469
Good grief, psft, I'm sorry. For some reason I thought this was a VB6 app running as a service. Sorry! No matter, although it does generally mitigate against the dialogs being routed to the event viewer :)

So when you start procmon nothing happens?? You should get the procmon activity window (after a licensing dialog, I think). You should also get an initial filter dialog to allow you to select what to monitor.

If you've got the source, I'd start thinking about adding the logging and finding out where this beast is dying on you.

LEt me know what happens on procmon.



0
 
LVL 1

Author Comment

by:psft
ID: 35492230
Still no solution, procmon is running, nothing jumped out at me when I was monitoring the service starting...

This might be helpful for you to know.

When running the command : telstat -a

On the Windows 7 PC it is NOT LISTENING to port "8252"

On the Windows XP PC it IS LISTENING to port "8252"

Its not because for sure because the XP machine is behind the same firewall.  And the Firewall was stopped.

Ideas?
0
 
LVL 7

Expert Comment

by:OklahomaDave
ID: 35492401
Then it sounds to me like we have to start diagnosing the startup problems under Windows 7, and that may mean hacking source to put in more logging to find out precisely where its failing. I think your service is starting and running, but is encountering an error when it tries to set up listening on that port, and hangs. The only way I can think of to get more detail is to add logging to the service itself.

If you've turned off the firewall on the Windows 7 box, about the only other thing I could think of beyond logging in the service itself to detect the failure would be whether there was some additional layer of antivirus or intrusion detection software on that box blocking network access for that service.



0
 
LVL 1

Author Comment

by:psft
ID: 35492970
ERRORS while debugging service and trying to connect to it are as follows:

Could not connect to net.tcp://localhost:8251/XYZ/Configuration. The connection attempt lasted for a time span of 00:00:01.0090000. TCP error code 10061: No connection could be made because the target machine actively refused it 127.0.0.1:8251.

private const string CONTROL_ENDPOINT_NAME = "TCPControl"/*"LocalControl"*/;
private const string CONFIGURATION_ENDPOINT_NAME = "TCPConfiguration"/*"LocalConfiguration"*/;
.
.
m_server = new XYZControlClient(new InstanceContext(m_callback), CONTROL_ENDPOINT_NAME);
m_configureServer = new XYZConfigurationClient(CONFIGURATION_ENDPOINT_NAME);
.
.
m_server.StartControlSession(null);

Open in new window


These errors are seen in the event log.

A first chance exception of type 'System.ServiceModel.EndpointNotFoundException' occurred in mscorlib.dll
A first chance exception of type 'System.ServiceModel.CommunicationObjectFaultedException' occurred in mscorlib.dll
0
 
LVL 7

Accepted Solution

by:
OklahomaDave earned 2000 total points
ID: 35493231
This is a booger!

Just for grins, can you verify that there is no special antivirus software on that box? Some of them will act like pseudo-firewalls and block outbound TCP connections. When you start getting the "actively refused" type of messages, it sure sounds like something between your app and the service is getting in the way, especially when the same setup works on an XP box.

=David

0
 
LVL 1

Assisted Solution

by:psft
psft earned 0 total points
ID: 35768799
I was not able to resolve a solution and have passed it on for other people to address.  Dave Thank you for your help!  You had many great ideas for others to try.  I'm not sure if I can give you points for all your help or how that works.
0
 
LVL 1

Author Closing Comment

by:psft
ID: 35806988
Lots of great ideas and info but not final solution
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Possible fixes for Windows 7 and Windows Server 2008 updating problem. Solutions mentioned are from Microsoft themselves. I started a case with them from our Microsoft Silver Partner option to open a case and get direct support from Microsoft. If s…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.
This Micro Tutorial will give you a introduction in two parts how to utilize Windows Live Movie Maker to its maximum editing capability. This will be demonstrated using Windows Live Movie Maker on Windows 7 operating system.
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question