Hosting WCF in IIS7 with multiple Website Bindings
In IIS7 (should be similar in IIS6 as well) Manager, you can create a website under Sites with multiple Bindings so that the website root can be accessed by different combinations of host name, IP and port etc. However, if you have a WCF service that you intend to host in this website, there are some explicit configuration that must follow.
Firstly, understand that a Website in ISS is an Application that runs in an Application Pool. As such, it is allowed to have a folder named “bin” or a bin folder that will store dll binaries that your WCF configuration .svc and web.config file will load. The .svc and web.config file can reside in any folder or subfolders in the Website Application, but it will always load the binaries from the Application’s bin folder.
When multiple Bindings are set on the Website, you will need additional settings to web.config to explicitly state the bindings that the WCF service can be reached.
<system.serviceModel>
<serviceHostingEnvironment>
<baseAddressPrefixFilters>
<add prefix="net.tcp://first.host.name:80"/>
<add prefix="http://another.host.name:9000"/>
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
</system.serviceModel>
Or…
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true">
</serviceHostingEnvironment>
</system.serviceModel>
However, this then requires that the WCF service be hosted in an Application domain separate from Website Application. One solution is to put the WCF web.config, .svc and the bin folder into a subfolder, and make the subfolder an Application itself. Because the subfolder is now an Application (within the Website Application), it will have it will load the dll from its own bin folder.
WrapPanel not wrapping as ListBox ItemsPanel
When using a WrapPanel as the ItemsPanel for a ListBox as such
<ListBox> <ListBox.ItemsPanel> <ItemsPanelTemplate> <WrapPanel/> </ItemsPanelTemplate> </ListBox.ItemsPanel> ... <!-- ListBoxItems --> </ListBox>
The WrapPanel may not wrap the items as expected. This is because of WPF’s width and height sizing issue. Depending on the type of Panel that the ListBox is contained in e.g. StackPanel, Grid, etc the width of the ListBox will be resolved differently. If the width of the ListBox is allowed to resize infinitely e.g. “size to fit contents” in the Orientation of the WrapPanel, then WrapPanel will never need to wrap and a scrollbar will appear on the ListBox to allow scrolling in that direction instead.
The ScrollBars that appear on the ListBox is due to a ScrollViewer internal to ListBox. You can use the attached property of the ScrollViewer to disable the scrollbar so that the ListBox is forced to wrap e.g.
<ListBox ScrollViewer.HorizontalScrollBarVisibility="Disabled"> <ListBox.ItemsPanel> <ItemsPanelTemplate> <WrapPanel/> </ItemsPanelTemplate> </ListBox.ItemsPanel> ... <!-- ListBoxItems --> </ListBox>
Alternatively, as mentioned before, tweak the width resolution mechanism up the parent tree to get the desired result.
How to create Visual Studio Setup Project for VSTO add-in
This is written in the context of an Visual Studio 2010 and VSTO Excel add-in, that I created and had to deploy using the setup project after exploring all other options including ClickOnce, Wix, InstallShield and what-not. As it turns out, the Visual Studio Setup Project remains to be the easiest to understand and use. Yes, it has its limitations, but for the majority of the cases, I am sure it will just work.
First off, create the Setup Project the way you would with any other projects. The project will appear in the project explorer and here is the first big tip: All the features of the setup project are tucked into the context menu of the project icon.
If you look at the project tree and the main workarea, you don’t see very much and it’s not obvious how to get started right away. But if you right click on the project icon, you see that besides the usual “Build”, “Rebuild”, “Properties” and the file options, you also get new options “Install”, “Uninstall” and the unassuming “Add” and “View” submenus. “Install” and “Uninstall” are self-explanatory, but the “Add” and “View” submenus are not the usual lads. “Add” allows you to add files to be installed onto the client system, and “View” allows you to change various settings that you would want to. Finally, the obscure “Pre-requisite” button is in the properties dialog you get when you click on “Properties” in the context menu.
Start customizing your setup.exe by adding files. The project automatically detects the primary output files (dll, exe) and dependencies, but you must remember to manually check and add additional content and configuration files as required by your application. In terms of my VSTO application, I must manually add the *.manifest and *.vsto files and other content files that my add-in access during runtime.
Then we set the default install location (or Application Folder) to [LocalAppDataFolder][Manufacturer]\[ProductName] under View > File System.
Next, use the view menu to customise any other settings you need. In the case of my VSTO add-in, a registry entry is required for excel to detect and load my add-in. The registry key to create is HKCU\Software\Microsoft\Office\Excel\Addinds\MyVSTOAddInName with following keys:
- String Description = “Description for my add-in”
- String FriendlyName = “Short name for my add-in”
- DWORD LoadBehavior = 3
- String Manifest = “[TARGETDIR]vstofilename.vsto|vstolocal”
Note that [TARGETDIR] is a variable in Setup Project to inthe client install directory for our application files.
Finally, for my VSTO application, I need to remove the option for user to install my application “for all users”, so I go to view > User Interface > Installation Folder and under its properties set InstallAllUsersVisible to False.
This would be a most basic setup and really, the trick is still to know that all the features are found in the context menu so that you know what lingo and terminology to use and the rest is pretty much handled by Google!
How you should use Google and Wikipedia, not let them replace you.
http://www.scientificamerican.com/article.cfm?id=do1es-constant-googling-really-make-you-stupid
Not stupid if you know how to use it.
Some lecturers say Wikipedia is evil as anybody can edit and you get nonsense out of it.
Not if you know what Wikipedia is and how to use it.
SUBST command line tool to shorten file paths
The shadow copy service provides snapshots of the file volumes but appends a time stamp in the path. This may cause the resulting path to be longer than the system can handle. In order to copy files from the shadow copy “previous versions”, you need to shorten the path name.
The SUBST command line tool can be used to substitute part of the path with a drive letter so that the eventual source path is shortened. To get the path of the shadow copy, right click the folder in shadow copy, go to properties and the full path with the time stamp will be shown in the properties dialog.
Combined with ROBOCOPY, you can write a batch file to recovery lost file quite quickly:
cd c:\users\admin\desktop SUBST A: /D SUBST B: /D SUBST A: S:\@GMT-2012.09.21-04.00.21\Data SUBST B: G:\Data ROBOCOPY A: B: /XO /S /E /LOG:robocopy_log.txt /FP /NS /NC SUBST A: /D SUBST B: /D echo Copy Completed.
Winforms controls not painting correctly, messed up.
While writing a custom paint routine you may come across a strange phenomenon where some of the controls on the Winforms are not painting correctly or even appearing at times. This is usually due to Control.Invalidate() being called recursively, and the API tries to keep on painting what is important and defers the painting of other controls such that they do not appear where they should have. This problem is most elusive if Control.DoubleBuffered is set to true, otherwise, it will be obvious for the flickering due to very fast painting on the front buffer.