Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - How to call a web service from Power Shell

Reply
 
Old 06-15-2006   #1 (permalink)
Nicola Attico


 
 

How to call a web service from Power Shell

Hello,

can you give me a hint about how to call a web service using PS ?

I know .NET is supposed to be integrated with web services standards and
that I can access .NET objects from Power Shell

Thanks in advance,

Nicola Attico

My System SpecsSystem Spec
Old 06-15-2006   #2 (permalink)
Keith Hill [MVP]


 
 

Re: How to call a web service from Power Shell

"Nicola Attico" <NicolaAttico@discussions.microsoft.com> wrote in message news:F589D99A-AB34-4A00-A080-24B8D560963A@microsoft.com...
> Hello,
>
> can you give me a hint about how to call a web service using PS ?
>
> I know .NET is supposed to be integrated with web services standards and
> that I can access .NET objects from Power Shell


In order to do this you will need to setup PS environment to enable VS 2005 tools. Just "dot" the attached PS1 script into your shell and that should work assuming you have VS 2005 installed. Now here's how to acces one particular web service. Note that the first two lines create a proxy assembly which takes care of the communication to the web service. On line 3 and 4 we load the assembly and then create the WeatherForecast proxy object. Then on line 5 we call one of its methods. It returns an XML document which we store in $forecast. BTW, you can use Reflector or VS's Object Browser to see the other methods in the assembly (or you can load up the WeatherForecast.cs file to see the nitty gritty proxy details).

PoSH 1> wsdl.exe http://www.webservicex.net/WeatherForecast.asmx?WSDL
PoSH 2> csc /t:library WeatherForecast.cs
PoSH 3> [Reflection.Assembly]::LoadFrom("$pwd\WeatherForecast.dll")
PoSH 4> $weatherService = new-object WeatherForecast
PoSH 5> $forecast = $weatherService.GetWeatherByZipCode(80526)
PoSH 6> $forecast

Latitude : 40.54729
Longitude : 105.1076
AllocationFactor : 0.008857
FipsCode : 08
PlaceName : FORT COLLINS
StateCode : CO
Status :
Details : {WeatherData, WeatherData, WeatherData, WeatherData...}

PoSH> $forecast.Details |select Day, MaxT*F, MinT*F

Day MaxTemperatureF MinTemperatureF
--- --------------- ---------------
Thursday, June 15, 2006 84 54
Friday, June 16, 2006 80 50
Saturday, June 17, 2006 85 55
Sunday, June 18, 2006 91 58
Monday, June 19, 2006 95 59
Tuesday, June 20, 2006 94 58
Wednesday, June 21, 2006 90 56

See it gets a bit warmer here in Colorado than some folks would suspect. :-)

Enjoy!
--
Keith
My System SpecsSystem Spec
Old 06-15-2006   #3 (permalink)
DBMwS


 
 

RE: How to call a web service from Power Shell

My System SpecsSystem Spec
Old 06-19-2006   #4 (permalink)
Nicola Attico


 
 

Re: How to call a web service from Power Shell

"Keith Hill [MVP]" wrote:

[..skip..]
> Now here's how to acces one particular web service.

[..skip..]

Thanks folks!

this really gave me a great insight!

Nicola Attico


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Power Shell? PowerShell
Power Shell no arranca PowerShell
power shell in a script PowerShell
Executing Power Shell Scripts from Windows Shell PowerShell
power shell in x64 PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46