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.