Sunday, 27 December 2009

SharePoint timer job and settings or configuration file

I got a question that what is the case when a SharePoint timer job needs a configuration file? Because, I really need the configuration settings for a timer job which I deployed. Because I got a requirement where I need to use the web service in a timer job and it needs the httpBindings and the endpoints. I can't place them in web.config of the web site as I can't access it here. But, I can access the web.config file as I discussed it in my previous post. I can get all the bindings and endpoints from web.config and create a c# bindngs object. And for the web service I passed the binding and that didn't solve the problem. Somehow, I got the below exception.

WSE012: The input was not a valid SOAP message because the following information is missing: action.

So, I started thinking in different ways and out of box. Below is the way how I approached towards the solution.

  • Everyone knows that all the timer job runs with the help of the OWSTIMER.EXE.
  • If you take a look at the console application, c# project and if you add the app.config file to the project then in your bin folder, you will see two files like if it is c# project then projectname.dll and projectname.dll.config and if it is console application then projectname.exe and projectname.exe.config.
  • So, what you understood from it? for dll or exe there is associated config file if that project contains app.config file.
  • What will happens when we use the dll or try to run the exe, the related config file also loads into memory and you can use the config file in the dll or exe.
  • There my thought starts and I want to repeat the same concept for the OWSTIMER.EXE too. 
  • Find the location of where OWSTIMER.EXE is reside in. Generally, the location is at "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\BIN\OWSTIMER.EXE". So, go to that location and create a file named OWSTIMER.EXE.CONFIG.
  • Open it in notepad and place all the settings code in it. Save it.
  • Now, it's time to restart the timer service. So, go to services and find SharePoint Timer Service. And restart it.
  • Now, run the timer service and you see everything is running successful. I mean all the settings will be loaded and run.

Note: Try to include all the settings in the config file within these tags.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
</configuration>

Hope this detailed post will help you to improve knowledge and how to think out of box. Love to hear comments.

No comments:

Post a Comment