Hosting WCF in IIS 7.0 / Windows 2008

by Mikael Henriksson 25. November 2009 11:57

If found this to be helpful

  1. Run an elevated command prompt
  2. Run the following command:
    "%windir%\Microsoft.NET\Framework\v3.0\Windows Communication Foundation\ServiceModelReg.exe" -r -y
  3. Last and also very important is the need for a base address, it seems IIS 7 does not figure this out by itself:
  4. <system.serviceModel>
    	<services>
    		<service name="RESTService.Service" 
    				 behaviorConfiguration="Default">
    			<host>
    				<baseAddresses>
    					<add baseAddress="http://localhost:80/" />
    				</baseAddresses>
    			</host>
    			<endpoint address="" 
    					  behaviorConfiguration="Default" 
    					  binding="webHttpBinding" 
    					  contract="RESTService.Service" />
    		</service>
    	</services>
    </system.serviceModel>

Just speficy the baseAddress and you should be good to go. Navigate to your svc file and you can start consuming it.

Tags:

WCF | Windows Server

Synchronizing web sites with Web Deployment Tool

by Mikael Henriksson 26. August 2009 14:43

First of all we set up a DFS (Distributed File System) because having to copy the website files from Team City to two or three servers is a pain in the a**. Now we only copy the files to one server and it is synchronized with the others but hey what if you need to change something in the IIS manager? Well then there is the Web Deployment Tool. First install it then use it.

The following script should be run from server01 to synchronize the changes to server02. It does not take a backup of server02’s current configuration. It also does not create any application pools (have not figured that one out yet). First open a command prompt as administrator (otherwise it will give you a nice explanation about why). Second: in command prompt, navigate to “C:\Program Files\IIS\Microsoft Web Deploy” and then run the following two commands.

msdeploy -verb:getDependencies -source:apphostconfig="www.domain.com"
msdeploy -verb:sync -source:apphostconfig="www.domain.com" -dest:apphostconfig="www.domain.com",computername=server02 -whatif > msdeploysync.log

Forgot to mention the www.domain.com is actually the name of the website in IIS manager. The first line is to make a configuration out of dependencies. The second line executes this config against the server of your choice (-computername)

Tags: , ,

Windows Server | IIS | ASP.NET

How do I log from asp.net to Event Log?

by Mikael Henriksson 27. January 2009 19:00

This has been bugging me for quite some time with throwing exceptions when I try to log from an asp.net page to Event Log. The solution is quite simple but it eludes me why nothing has been written about. At least not anywhere I have looked.

  1. Go to run (win+r) type in regedt32.
  2. Navigate to HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\EventLog
  3. Right click, select permissions and Add the ASPNET account (IUSR as well????) with full rights
  4. Make sure that all child objects get the same rights

Done, now you can start logging to the event log.

Tags:

Windows Server

How do I configure Windows 2003 Server for Remote Applications?

by Mikael Henriksson 27. January 2009 18:59

My first try at this was to just let the user run a program set from "environement" under Users & Computers. It works ok, but the users where not satisfied with having to relogin if my application crashed. Second try was today and it's not completely finished but I'm getting there. Since the users are logging on to the server from thin clients I dont want them to be able to change anything on the server. Thats why I only allowed a program to be run in the remote desktop session. As soon as the application ended the remote desktop session ended.

Now this is how you do it!

  1. Download and install FC81887&displaylang=en" title="Group Policy Management Console">Group Policy Management Console
  2. Create a new security group in "Users & Computers"
  3. Open up gpmc.mmc and create a new policy, preferably named like the the security group so that I may easily be able to distinguish it.
  4. Add the newly created security group to the policy and make sure the group has read and apply rights to the policy.
  5. Remove most things from Start Menu, Windows Explorer and desktop. I might also like now want to remove access to control panel and task manager.
  6. Make sure that I hide the system drive (C:\) and have the users run their applications from let's say the D: drive with full access to a particular folder.
  7. Create a .vbs script to launch the application
  8. Place a shortcut to the application should it crash
  9. Do a policy update "cmd.exe gpupdate /force"

I found a great article to help me out. I did need to change a few things in the script though this is what my script looks like.

 

 

On Error Resume Next
Set fs = CreateObject ("Scripting.FileSystemObject")
Set WshShell = WScript.CreateObject ("WScript.Shell")

'Get the username and profile directory
MUser = WshShell.ExpandEnvironmentStrings ("%USERNAME%")
MUserProfile = wshShell.ExpandEnvironmentStrings("%USERPROFILE%")

'Delete icons
fs.DeleteFolder MUserProfile & "\Start Menu\Programs\Accessories",True
fs.DeleteFile  MUserProfile & "\Start Menu\Programs\*.lnk"

'Run the app

wshShell.Run "D:\Company\bin\%USERNAME%\Application\app.exe"

' Connect to wmi
set objWMIService = GetObject("winmgmts:root\cimv2")
Do
  found = false
' List the processes
strQuery = "Select * from win32_process where name='app.exe'"
set colProcesses = objWMIService.ExecQuery(strQuery)

for each proc in colProcesses

   ' Get the reference class linking processes to sessions to get the session object path
   strQuery = "References of {win32_process.handle='" & proc.handle & "'} where ResultClass=Win32_SessionProcess"
   set colSessionReferences = objWMIService.ExecQuery(strQuery)

   for each oSessionReference in colSessionReferences
      'Get associators of the session object that are user accounts (linked by win32_loggedonuser)
      strQuery = "Associators of {" & oSessionReference.antecedent & "} where AssocClass=win32_LoggedOnUser"
      set colUsers = objWMIService.ExecQuery(strQuery,,48)
        for each user in colUsers
         if user.name = MUser then found = true
      next
   next
next
Loop While found = true

'Run the Windows 2003 logoff utility
wshShell.Run "c:\windows\system32\logoff.exe"

Sweet! All done! Thanks a bunch to Amit Zinman

 

Tags:

Windows Server

About the author

Life architect specialized in programming