Jayrock + PowerShell

11 views
Skip to first unread message

Atif Aziz

unread,
Jun 27, 2007, 5:10:09 PM6/27/07
to jay...@googlegroups.com
The latest Jayrock bits (available over ftp://ftp.berlios.de/pub/jayrock) add a PowerShell proxy to your JSON-RPC service so now you can automate and call into your service interactively from the PowerShell console. This was a little experiment inspired after stumbling across the PowerShell JSON Deserializer project.

Here's first using Jayrock from PowerShell to import JSON (nothing special here):

PS C:\> [Reflection.Assembly]::LoadFile("C:\Jayrock\bin\Jayrock.Json.dll")

GAC Version Location
- --- ---
False v1.1.4322 C:\Jayrock\bin\Jayrock.Json.dll

PS C:\> [Jayrock.Json.Conversion.JsonConvert]::Import('[{"title":"PowerShell"},{"title":"Test"}]')

Name Value
---- -----
title PowerShell
title Test

The bit of twist added now is that you can dynamically generate a PowerShell script from the server in order to call server-side methods of your service for administrative purposes. Here is how to download the PowerShell proxy (assuming the demo service supplied with Jayrock is running on localhost at the virtual path jayrock):

PS C:\> $wc = New-Object Net.WebClient
PS C:\> $wc.DownloadString('http://localhost/jayrock/demo.ashx?ps1proxy') | Invoke-Expression

The nice thing about this technique is that it does not even require you to change the script execution policy. You download the script over the web and shazam, just hydrate it into the context of your running shell. With this gives you is a function called DemoService (based on your service) that you can call to create an instance of the proxy:

PS C:\> $s = DemoService

Next, just start calling the methods of this object *interactively*...

PS C:\> $s.now()
2007-06-22T09:21:03.8324368-06:00
PS C:\> [int] $s.sum(123, 456)
579
PS C:\> $s.system_listMethods()
echo
echoObject
echoArgs
echoAsStrings
.
.
.
system.listMethods
system.version
system.about

If you pipe $s to Get-Member, you'll see how the proxy is setup. In other words...

PS C:\> $s | Get-Member

There a few limitations of the PowerShell proxy right now:

- It works only synchronously (not sure if async matters for admin tasks)
- It only understands UTF-8 responses
- It does not support HTTP-based authentication

Enjoy.

Atif Aziz

unread,
Jun 27, 2007, 5:16:13 PM6/27/07
to jay...@googlegroups.com
Forgot to mention the PowerShell JSON Deserializer project URL, but here it is now:
http://www.codeplex.com/PowerShellJSON
Reply all
Reply to author
Forward
0 new messages