Thursday, March 26, 2020

Hosting Restful services on Windows service using OWIN


Hosting Restful services on Windows service using OWIN

Code:

public partial class Service : ServiceBase
{
protected override void OnStart(string[] args)
        {
            StartOptions options = new StartOptions();
           options.Urls.Add("http://+:9889/DPE");
            _startup = WebApp.Start<OwinStartup>(options);
        }
}


Steps on server:

1.       Open command prompt in Administration mode.
2.      Run netsh show command and redirect output to another txt file
e.g.,netsh http show urlacl >"netsh_registeredurls.txt"
=>Displays/outputs the registered urls in the HTTP.sys settings
3.      If particular port present, delete all entries using netsh http delete command
e.g., netsh http delete urlacl url=http://+:9889/
4.      Uninstall service
5.      Add registered entry in HTTP.sys
e.g., netsh http add urlacl url=http://+:9889/ user=jeder (Note: jeder is Germany equivalent of Everyone)
6.      Install service
7.      Launch service

Tuesday, February 4, 2020

SlowCheetah: The TransformXml task was not found

To fix this, one just has to update the .csproj file of the particular project by adding this line - make sure you point to the correct path of "Microsoft.Web.Publishing.Tasks.dll"

<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v16.0\Web\Microsoft.Web.Publishing.Tasks.dll" />


<Target Name="BeforeBuild">
   <TransformXml Source="App.Base.config" Transform="App.$(Configuration).config" Destination="App.config" />
  </Target>

Saturday, January 11, 2020

Powershell script that will create shortcuts for client and service executables and to run all of them in one go it will also create a batch file.

Powershell script that will create shortcuts for client and service executables and to run all of them in one go it will also create a batch file.
It also takes care of launching the IIS express to host the webservice.


param(
        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [string]$SolutionFileDirectoryPath,
        [AllowNull()]
        [string]
        $ShortcutTargetLocation
)
$SolutionFileDirectoryPath=$SolutionFileDirectoryPath.TrimStart('"')
$SolutionFileDirectoryPath=$SolutionFileDirectoryPath.TrimEnd('"')
$PathExists = Test-Path $SolutionFileDirectoryPath
if ($pathexists -eq $false)
{
    write-host "missing or wrong parameters:"
    write-host "-solutionfiledirectorypath  directory path of solution file in source code(without trailing slash - \)"
    write-host "-shortcuttargetlocation     target location of services shortcut and batch file. Default location is current executable path of powershell script."
    return
}
If($ShortcutTargetLocation -eq $null -or $ShortcutTargetLocation -eq "")
{
    write-host "-ShortcutTargetLocation  Target location of services shortcut and batch file. Default location is current path"
    $ShortcutTargetLocation =$(Get-Location)
}
Else
{
    $PathExists = Test-Path $ShortcutTargetLocation
    If ($PathExists -eq $False)
    {
        write-host "missing parameter:"
        write-host "-ShortcutTargetLocation  Specified target path of services shortcut and batch file doesn't exist. Default location is current path"
        return
    }
}
$ShortcutTargetPath = Join-Path -Path $SolutionFileDirectoryPath -ChildPath "DCX.DPE.AKVService\bin\SQLExpress\DCX.DPE.Service.AKV.exe"
$ShortcutLocation = Join-Path -Path $ShortcutTargetLocation -ChildPath "DCX.DPE.Service.AKV.exe.lnk”
$WScriptShell = New-Object -ComObject WScript.Shell
$Shortcut = $WScriptShell.CreateShortcut($ShortcutLocation)
$Shortcut.TargetPath = $ShortcutTargetPath
$Shortcut.Arguments = "/c"
$Shortcut.Save()

$ShortcutTargetPath = Join-Path -Path $SolutionFileDirectoryPath -ChildPath "DCX.DPE.AKVService\bin\SQLExpress\DCX.DPE.Service.AKV.exe"
$ShortcutLocation = Join-Path -Path $ShortcutTargetLocation -ChildPath "DCX.DPE.Service.AKV.exe.lnk”
$WScriptShell = New-Object -ComObject WScript.Shell
$Shortcut = $WScriptShell.CreateShortcut($ShortcutLocation)
$Shortcut.TargetPath = $ShortcutTargetPath
$Shortcut.Arguments = "/c"
$Shortcut.Save()

$ShortcutTargetPath = Join-Path -Path $SolutionFileDirectoryPath -ChildPath "DCX.DPE.Service.Creta\bin\SQLExpress\DCX.DPE.Service.Creta.exe"
$ShortcutLocation = Join-Path -Path $ShortcutTargetLocation -ChildPath "DCX.DPE.Service.Creta.lnk”
$WScriptShell = New-Object -ComObject WScript.Shell
$Shortcut = $WScriptShell.CreateShortcut($ShortcutLocation)
$Shortcut.TargetPath = $ShortcutTargetPath
$Shortcut.Arguments = "/c"
$Shortcut.Save()

$ShortcutTargetPath = Join-Path -Path $SolutionFileDirectoryPath -ChildPath "DCX.DPE.Service.OpenItems\bin\SQLExpress\DCX.DPE.Service.OpenItems.exe"
$ShortcutLocation = Join-Path -Path $ShortcutTargetLocation -ChildPath "DCX.DPE.Service.OpenItems.exe.lnk”
$WScriptShell = New-Object -ComObject WScript.Shell
$Shortcut = $WScriptShell.CreateShortcut($ShortcutLocation)
$Shortcut.TargetPath = $ShortcutTargetPath
$Shortcut.Arguments = "/c"
$Shortcut.Save()

$ShortcutTargetPath = Join-Path -Path $SolutionFileDirectoryPath -ChildPath "DCX.DPE.Service.Qgroup\bin\SQLExpress\DCX.DPE.Service.Qgroup.exe"
$ShortcutLocation = Join-Path -Path $ShortcutTargetLocation -ChildPath "DCX.DPE.Service.Qgroup.exe.lnk”
$WScriptShell = New-Object -ComObject WScript.Shell
$Shortcut = $WScriptShell.CreateShortcut($ShortcutLocation)
$Shortcut.TargetPath = $ShortcutTargetPath
$Shortcut.Arguments = "/c"
$Shortcut.Save()

$ShortcutTargetPath = Join-Path -Path $SolutionFileDirectoryPath -ChildPath "DCX.DPE.Service.SoftwareManagement\bin\SQLExpress\DCX.DPE.Service.SoftwareManagement.exe"
$ShortcutLocation = Join-Path -Path $ShortcutTargetLocation -ChildPath "DCX.DPE.Service.SoftwareManagement.exe.lnk”
$WScriptShell = New-Object -ComObject WScript.Shell
$Shortcut = $WScriptShell.CreateShortcut($ShortcutLocation)
$Shortcut.TargetPath = $ShortcutTargetPath
$Shortcut.Arguments = "/c"
$Shortcut.Save()

$ShortcutTargetPath = Join-Path -Path $SolutionFileDirectoryPath -ChildPath "DCX.DPE.Service.Workflow\bin\SQLExpress\DCX.DPE.Service.Workflow.exe"
$ShortcutLocation = Join-Path -Path $ShortcutTargetLocation -ChildPath "DCX.DPE.Service.Workflow.exe.lnk”
$WScriptShell = New-Object -ComObject WScript.Shell
$Shortcut = $WScriptShell.CreateShortcut($ShortcutLocation)
$Shortcut.TargetPath = $ShortcutTargetPath
$Shortcut.Arguments = "/c"
$Shortcut.Save()

$ShortcutTargetPath = Join-Path -Path $SolutionFileDirectoryPath -ChildPath "DCX.DPE.Client\bin\SQLExpress\DCX.DPE.Client.exe"
$ShortcutLocation = Join-Path -Path $ShortcutTargetLocation -ChildPath "DCX.DPE.Client.exe.lnk”
$WScriptShell = New-Object -ComObject WScript.Shell
$Shortcut = $WScriptShell.CreateShortcut($ShortcutLocation)
$Shortcut.TargetPath = $ShortcutTargetPath
$Shortcut.Save()

$ShortcutTargetPath = Join-Path -Path $SolutionFileDirectoryPath -ChildPath "DCX.DPE.Client\bin\SQLExpress\DCX.DPE.Client.exe"
$ShortcutLocation = Join-Path -Path $ShortcutTargetLocation -ChildPath "DCX.DPE.Client.exe - PMULLAN.lnk”
$WScriptShell = New-Object -ComObject WScript.Shell
$Shortcut = $WScriptShell.CreateShortcut($ShortcutLocation)
$Shortcut.TargetPath = $ShortcutTargetPath
$Shortcut.Arguments = "APAC\PMULLAN"
$Shortcut.Save()

$BatFile = Join-Path -Path $ShortcutTargetLocation -ChildPath "LaunchDPEServices.bat"
If (Test-Path $BatFile) { Del $BatFile } #> #>
$BatchFileContent ="cd `"C:\Program Files (x86)\IIS Express\`"
start iisexpress /config:`"$(Join-Path -Path $SolutionFileDirectoryPath -ChildPath ".vs\DPE\config\applicationhost.config")`" /site:DCX.DPE.Web
cd /d `"$ShortcutTargetLocation`"
start `"DPE-AKVService`" /b `"DCX.DPE.Service.AKV.exe.lnk`"
start `"DPE-OpenItemService`" /b `"DCX.DPE.Service.OpenItems.exe.lnk`"
start `"DPE-WorkflowService`" /b `"DCX.DPE.Service.Workflow.exe.lnk`"
start `"DPE-QGroupService`" /b `"DCX.DPE.Service.Qgroup.exe.lnk`"
start `"DPE-SwMgmntService`" /b `"DCX.DPE.Service.SoftwareManagement.exe.lnk`""
Set-Content -Path $BatFile -Value $BatchFileContent -Encoding ASCII
write-host "Output files generated at `"$ShortcutTargetLocation`""

Wednesday, October 16, 2019

Logoff from a remote machine


Remote Logoff
  1. Open command prompt using remote machine login credentials
  2. Run QUser command to get list of remote sessions active for current logged in user
C:\Users\XYZ>QUser /server:servername
USERNAME              SESSIONNAME        ID  STATE   IDLE TIME  LOGON TIME
user1                                                            2  Disc     13+22:24  9/26/2019 9:48 AM
user2                          rdp-tcp#0                3  Active          .  9/26/2019 9:54 AM
user3 console                                             4  Active       2:14  10/7/2019 7:27 PM

  1. Run Loggoff command
C:\Users\XYZ>Logoff 3 /server:servername

Thursday, January 31, 2019

NPM config proxy behind corporate wall

NPM config proxy behind corporate wall

Edit C:\Users\Username\.npmrc as below:

strict-ssl = false
ca = null


Reference
https://fak3r.com/2015/07/31/howto-use-npm-behind-a-corporate-proxy/

Wednesday, January 2, 2019

Windows Docker Issue "Deny write access to fixed drive not protected by Bitlocker" con Win10 machine: Solved


Anyone facing this annoying issue in Win10 machine while running Windows Docker in Windows container can be solved by following the below steps:



One needs Admin access though.

Registry Settings
·         [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Policies\Microsoft\FVE]
"FDVDenyWriteAccess"=dword:00000000

Group Edit Policy
·         [Computer Configuration\Administrative Templates\Windows Components\BitLocker Drive Encryption\Fixed Data Drives]
“Deny write access to fixed drives not protected by BitLocker”=Disabled


This perhaps has been fixed in Win 10 17074 Build or higher.

Monday, December 3, 2018

Run WebServices and Windows services on IIS Express using command prompt or batch file

To run web and windows services in IIS Express through command prompt or batch file, we can create a batch file with the following changes:

cd "C:\Program Files (x86)\IIS Express"
start iisexpress /config:"path to your project source code repository\.vs\config\applicationhost.config" /site:WebSiteName
In applicationhost.config make changes as below:

  • Look for something like below for the WebSiteName above

  <sites>
            <site name="WebSite1" id="1" serverAutoStart="true">

  • Update physicalPath to correct path:

physicalPath="VirtualDirectory of WebSite" /> 

  • or copy all the bin(assembly) files as seen below:
    bin=> has all dll's of the web service
    Web.config should detail the hosting details of all services.




Other Windows services can be started as below:

  1. Create a shortcut to the windows service with command line arguments if any.
  2. In batch file add this line:
  3. start "Service title" /b "Path of shortcut to windowsservice.exe shortcut"