Msmq and WCF Service - windows-services

I have created a WCF service using the NetMsmq binding for which i created a private queue on my machine and executed the project. This works fine as such and my WCF service is started and accesses the message using the queue in the debugging environment. Now, I wanted to host the service using the windows service and for the same I created a new project and windows installer as well (This service runs under Local System Account). Then I tried installing this windows service using the InstallUtil command through the command prompt. When installation is happening and during the service host opening, I get an exception saying:
There was an error opening the queue. Ensure that MSMQ is installed and running, the queue exists and has proper authorization to be read from. The inner exception may contain additional information.
Inner Exception System.ServiceModel.MsmqException: An error occurred while opening the queue:Access is denied. (-1072824283, 0xc00e0025). The message cannot be sent or received from the queue. Ensure that MSMQ is installed and running. Also ensure that the queue is available to open with the required access mode and authorization.
at System.ServiceModel.Channels.MsmqQueue.OpenQueue()
at System.ServiceModel.Channels.MsmqQueue.GetHandle()
at System.ServiceModel.Channels.MsmqQueue.SupportsAccessMode(String formatName, Int32 accessType, MsmqException& msmqException)
Could anyone suggest the possible solution for the above issue? Am I missing any permissions to be set for the queue as well as the windows service, if so could you suggest where should these permissions be added?

Tom Hollander had a great three-part blog series on using MSMQ from WCF - well worth checking out!
MSMQ, WCF and IIS: Getting them to play nice (Part 1)
MSMQ, WCF and IIS: Getting them to play nice (Part 2)
MSMQ, WCF and IIS: Getting them to play nice (Part 3)
Maybe you'll find the solution to your problem mentioned somewhere!

Yes, it looks like a permissions issue.
Right click on your private queue from the Server Manager, and select Properties. Proceed to the Security tab, and make sure you have the right permissions in there for your Local System Account.
This is also confirmed in Nicholas Allen's article: Diagnosing Common Queue Errors, where the author defines the error code 0xC00E0025 as a permissions problem.

I ran into same problem, here is the solution.
Right click "My Computer" --> Manage. In Computer Management window go to "Services and Applications --> Message Queueing --> ur queue", select ur queue and access properties. Add the user running ur WCF application and give full access. This should solve the issue.

Can simple be that the service can't find the it's queue.
The queue name must exact match the endpoint address.
Example:
net.msmq://localhost/private/wf.listener_srv/service.svc
points to local queue
private$\wf.listener_srv\service.svc
If queue name and endpoint are according to each other, then is most like that the credentials defined on the IIS pool don't grant access to the queue.

Related

TF246017: team foundation server could not connect to the database

I am facing a problem with logging into TFS. I get the following error:
Exception Message: TF246017: Team Foundation Server could not connect
to the database. Verify that the server that is hosting the database
is operational, and that network problems are not blocking
communication with the server. (type SoapException)SoapException
Details:
Hi the below steps worked for me.
Select Application Tier in the TFS Administration Console.
In the Application Tier Summary which contains the Service Account details.
Click Reapply Account.
I know this is old, but here was my situation:
We have 11 collections on our instance, 2 were failing with this error, showing me it wasn't an access / connection issue. Checking Event Viewer (as #Andy Li-MSFT suggests) showed it was
A timeout occurred while waiting for memory resources to execute the query in resource pool 'default' (2). Rerun the query.
Checking task manager showed the culprit - elastic search was using well over 2GB of memory. I killed the service, the collections applied the patch quickly without issue.
Looks like I need to ask our server admins to give us a bit more memory....
Please check below thing to narrow down the issue:
Make sure you are the member of the Administration Console Users.
Otherwise you cannot access the Admin Console.
Make sure the SQL Server is stated and available, and the network
connectivity is OK.
Check the Service Account, make sure the Service Account has been added in
SQL Server.
You can also refer to the solution in below link to fix the issue:
https://www.ganshani.com/alm/tfs/visual%20studio/solved-tf246017-team-foundation-server-could-not-connect-to-the-database/
If above solution can not resolve the problem, please check the Event log. The Windows Event Log is a good candidate where to look for the potential cause.
For me I've solved the issue by changing the recovery mode Simple -> Full in the database.
Please refer to: https://www.mssqltips.com/sqlservertutorial/3/sql-server-full-recovery-model/

Rebus MVC subscriber on remote machine

I've got a rebus server process running on one machine and an MVC website on another. I configure the message routing in the MVC website with a local input and error queue and the destination pointing to the queue myinputqueue#BusServer and when it runs it sends the subscription message without error but nothing seems to appear on the destination queue. The receiving bus never acknowledges it or creates a subscription entry.
It's using msmq as the transport and all queues have full permissions to the Everyone group.
I'm assuming I've not configured something correctly so I hope this is the right forum to raise the question.
Appreciate any help.
Even though Everyone has access to the queues, and that sounds like there's nothing in the way of communicating freely, I'm not sure that it works that way.
In any case, I suggest you make sure your IIS app pool is runnig with some dedicated service user identity, which you can also use as the user account under which your server process is running.
With MSMQ, messages are never lost - so in your case, the subscription message is most likely sitting in an outgoing queue on the web server machine, or it might have been moved to the "Transactional dead-letter queue" which is where MSMQ ends up moving stuff that it cannot find a place for.
Could you try and take a look at the outgoing MSMQ queues and/or the transactional dead-letter queue to see if it's a user rights problem that is haunting you?

Nofity User some message from a windows service

I have created a windows service which gets soem info from database and I want to notify user based on the info retreived from the DB. How can I notify user from a windows service using system tray notification? Can you please show me some sample (using IPC mechanism) to get the return value of a method used in a windows service in a system tray notification?
Thanks in advance.
There are several options such as these:
Sockets: (Not too difficult to write, has firewall problems) You can find samples for it almost everywhere.
External WinForm: (The easiest method, has security problems and might blocked by
some antivirus apps) Just create a winForm with the ability to go into
the windows notification area and then tell the service to run its
exe file.
Named Pipes: (Probably the most difficult, but it's the recommended
solution) Here is a Code Project sample.
Other tricks like: Create a hidden winform project (ShowInTask=false) and put it in StartUp. provide it with a FileSystemWatcher object and make it watch for a certain file which the service creates or deletes it to signal the winform.

Is it possible to programmatically determine if my app is running as a Windows Service? [duplicate]

How can I tell if the application my code is running in, is it in a service or an application? Why do I want to know this - I'm writing some code that is injected into the target application and that code has no way of knowing this information up front, so it has to work it out itself.
I cannot rely on any code being called from the service control manager, start, stop, or command line parameters.
I'm currently looking at GetConsoleWindow() which I hope will return NULL for a service (no console) and a window handle for any application (has a console). Not sure how valid this assumption is.
Any ideas for a better solution?
Search the current process id (GetCurrentProcessId) from the list of all running services (EnumServicesStatusEx)?
The assumption of GetConsoleWindow() is not valid.
It seems to me that you care about the context of your process more. Are you asking that if your program is running in service context or the user session? If so, use ProcessIdToSessionId() http://msdn.microsoft.com/en-us/library/aa382990%28v=VS.85%29.aspx to get your session id and you will know it.
Use WMI to query for Win32_Service instances where 'ProcessId=MyProcessid'. If there is no match, then your process is not a service.
Background on WMI app creation in C++ here.
For Windows Vista or later you can check the session id. Session 0 is reserved for services and non-interactive programs. User sessions start from 1.
Use OpenProcessToken to get the current process token. Then use CheckTokenMembership to see if the token includes the WinServiceSid well-known SID.

Service Watch-dog design

I am working on a legacy product which has seven Windows services and a user interface. There are some bugs in the services which causes crash in every 10-15 days. I need to write an application to monitor the state of the services. If the services get crashed I need to send an e-mail to the administrator to start the services.
I am not able to use the auto recovery process since during some of the crashes, the Microsoft error report dialog or some other dialogs appears and the service is consider running till the message is acknowledged.
So, I am planning to go for this individual application / watch-service to monitor the crashes until the bugs in the original services are completely fixed.
Please share your views on the design of the watch-dog service.
Thanks.
From you question I understood that windows can't tell if the service ends because it shows a dialouge. If windows can't detect that the service has shutdown how is another application.
you will have to find so evidence that the process is doing what is supposed to do. checking that a log file is growing or seeing if events are being written is the simplest thing off hand.
You're question suggests that windows service recovery does not get triggered because of a an error dialog not being clicked. Perhaps what you need is something to detect that the error dialog is open and click the button. This way, the service can exit successfully and windows service recovery can kick in.
I have attached a program I use to automatically click annoying clearcase dialogs. Below is a sample config file that drives the program. All you need to do is to add a new line of clickInfo and fill in the correct window and button captions.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="clickConfiguration" type="ClickButton.ClickConfigurationSection, ClickButton"/>
</configSections>
<clickConfiguration>
<clickInfo windowName="ClearCase" buttonName="Proceed" />
</clickConfiguration>
</configuration>
Hope it helps!
If you cannot fix those services but can "expose" them as an HTTP resource on Internet, you can use online website monitoring services to periodically check if the service(s) are still on. Create a small website that knows how to "ping" your service(s) locally and request its page(s) on a schedule by one of those monitoring services.
I know several of such services: http://www.setcronjob.com/, http://www.webcron.org/, http://scheduler.codeeffects.com. The last one can even monitor your HTTP resources on your private network but this feature is not free. Hope this helps.
Funny how you need to hand-edit the registry to disable Drwatson and there's a commandline to enable it back ;) here, check this Microsoft KB: http://support.microsoft.com/kb/188296

Resources