Showing posts with label Script. Show all posts
Showing posts with label Script. Show all posts

November 14, 2009

Invoking WCF from PowerShell

To invoke WCF from PS

1. Environment setup for PS

2. Create & bind proxy

3. Use API to invoke WCF

Following script demonstrates how to access Calculator service using PS.

Windows PowerShell
Copyright (C) 2006 Microsoft Corporation. All rights reserved.

PS C:\Documents and Settings\amungale\Desktop\WCF\HelloService\bin\Debug> cd "C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin"
PS C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin> .\vs80vars.ps1
PS C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin> .\svcutil.exe http://localhost:8000/ServiceModelSamples/service?ws
dl
Microsoft (R) Service Model Metadata Tool
[Microsoft (R) Windows (R) Communication Foundation, Version 3.0.4506.2152]
Copyright (c) Microsoft Corporation. All rights reserved.

Attempting to download metadata from 'http://localhost:8000/ServiceModelSamples/service?wsdl' using WS-Metadata Exchange
or DISCO.
Generating files...
C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\CalculatorService.cs
C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\output.config
PS C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin> csc /t:library CalculatorService.cs /r:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\System.ServiceModel.dll"
Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.3053
for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727
Copyright (C) Microsoft Corporation 2001-2005. All rights reserved.

PS C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin> [Reflection.Assembly]::LoadWithPartialName("System.ServiceModel")

GAC Version Location
--- ------- --------
True v2.0.50727 C:\WINDOWS\assembly\GAC_MSIL\System.ServiceModel\3.0.0.0__b77a5c561934e089\System.ServiceModel...


PS C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin> [Reflection.Assembly]::LoadFrom("$pwd\CalculatorService.dll")

GAC Version Location
--- ------- --------
False v2.0.50727 C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\CalculatorService.dll


PS C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin> $wsHttpBinding = new-object System.ServiceModel.WSHttpBinding
PS C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin> $endpoint = new-object System.ServiceModel.EndpointAddress("http:/
/localhost:8000/ServiceModelSamples/service"
)
PS C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin> $calcService = new-object CalculatorClient($wsHttpBinding, $endpoi
nt)
PS C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin> $calcService.Add(3,4)
7

Additional References:

http://keithhill.spaces.live.com/blog/cns!5A8D2641E0963A97!512.entry
http://keithhill.spaces.live.com/blog/cns!5A8D2641E0963A97!645.entry
 

October 04, 2009

How to target compilers in PS?

If PS is targeting any other compiler than you need then simply change the compiler directory to make sure it compiles with correct version of .NET.

E.g.

cd 'C:\WINDOWS\Microsoft.NET\Framework\v3.5'
.\csc /t:library 'C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\generatedClient.cs' /r:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\System.ServiceModel.dll"

Following script you can use to setup environment variables for VS2005

   1:  $env:VSINSTALLDIR="$env:ProgramFiles\Microsoft Visual Studio 8"
   2:  $env:VCINSTALLDIR="$env:ProgramFiles\Microsoft Visual Studio 8\VC"
   3:  $env:DevEnvDir="$env:VSINSTALLDIR\Common7\IDE"
   4:  $env:FrameworkSDKDir="$env:VSINSTALLDIR\SDK\v2.0"
   5:  $FrameworkPath=$([System.Runtime.InteropServices.RuntimeEnvironment]::GetRuntimeDirectory())
   6:  $env:FrameworkDir=$(split-path $FrameworkPath -Parent)
   7:  $env:FrameworkVersion=$(split-path $FrameworkPath -Leaf)
   8:  $env:PATH="$env:VSINSTALLDIR\Common7\IDE;$env:VCINSTALLDIR\BIN;$env:VSINSTALLDIR\Common7\Tools;$env:VSINSTALLDIR\Common7\Tools\bin;$env:VCINSTALLDIR\PlatformSDK\bin;$env:FrameworkSDKDir\bin;$env:FrameworkDir\$env:FrameworkVersion;$env:VCINSTALLDIR\VCPackages;$env:PATH"
   9:  $env:INCLUDE="$env:VCINSTALLDIR\ATLMFC\INCLUDE;$env:VCINSTALLDIR\INCLUDE;$env:VCINSTALLDIR\PlatformSDK\include;$env:FrameworkSDKDir\include;$env:INCLUDE"
  10:  $env:LIB="$env:VCINSTALLDIR\ATLMFC\LIB;$env:VCINSTALLDIR\LIB;$env:VCINSTALLDIR\PlatformSDK\lib;$env:FrameworkSDKDir\lib;$env:LIB"
  11:  $env:LIBPATH="$FrameworkPath;$env:VCINSTALLDIR\ATLMFC\LIB
Following script you can use to setup environment variables for VS2008
   1:  $env:VSINSTALLDIR="$env:ProgramFiles\Microsoft Visual Studio 9.0"
   2:  $env:VCINSTALLDIR="$env:ProgramFiles\Microsoft Visual Studio 9.0\VC"
   3:  $env:DevEnvDir="$env:VSINSTALLDIR\Common7\IDE"
   4:  $env:FrameworkSDKDir="$env:VSINSTALLDIR\SDK\v3.5"
   5:  $FrameworkPath=$([System.Runtime.InteropServices.RuntimeEnvironment]::GetRuntimeDirectory())
   6:  $env:FrameworkDir=$(split-path $FrameworkPath -Parent)
   7:  $env:FrameworkVersion=$(split-path $FrameworkPath -Leaf)
   8:  $env:PATH="$env:VSINSTALLDIR\Common7\IDE;$env:VCINSTALLDIR\BIN;$env:VSINSTALLDIR\Common7\Tools;$env:VSINSTALLDIR\Common7\Tools\bin;$env:VCINSTALLDIR\PlatformSDK\bin;$env:FrameworkSDKDir\bin;$env:FrameworkDir\$env:FrameworkVersion;$env:VCINSTALLDIR\VCPackages;$env:PATH"
   9:  $env:INCLUDE="$env:VCINSTALLDIR\ATLMFC\INCLUDE;$env:VCINSTALLDIR\INCLUDE;$env:VCINSTALLDIR\PlatformSDK\include;$env:FrameworkSDKDir\include;$env:INCLUDE"
  10:  $env:LIB="$env:VCINSTALLDIR\ATLMFC\LIB;$env:VCINSTALLDIR\LIB;$env:VCINSTALLDIR\PlatformSDK\lib;$env:FrameworkSDKDir\lib;$env:LIB"
  11:  $env:LIBPATH="$FrameworkPath;$env:VCINSTALLDIR\ATLMFC\LIB"

January 15, 2006

Javascript events for ASP.NETcontrols

While using Java Script events with ASP .NET controls make sure that they are really JS events. E.g.
OnSelectedIndexChanged and OnTextChanged are server side events. If you try to use them from client side then they will not fire. In such case you need JS 'onchange' event.

February 01, 2003

Simple HTML/Script to zoom image on clicks

<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
</HEAD>
<script language="Javascript" event="onclick" for="Grphic">
Grphic.width *= 1.5 ;
Grphic.height *= 1.5 ;
</script>
<BODY>

<img src="images\seal.bmp" id=Grphic>