Sep 10, 2008

Call a Web Service with SharePoint Designer and PowerActivity

WARNING EXPLICIT SCRIPTS: The example is quiet complex!

  • Create a custom list "Power Snippets"
  • Add a multiple line plain text column, perhaps 60 lines, "PSScript"
  • Define any other list to attach the workflow (Title, Result as Rich Text)
  • Add your snippets to the list (e.g. my Get-WebServiceProxy script (Requirements for this script: Windows SDK (wsdl.exe) and .NET 3.5. )

image

image 

  • Use the snippet in SharePoint Designer. Add the "Execute PowerShell Activity to your SPD Workflow. Define a workflow variable named "result" type of text to store the result of the web service request. Insert the following script:

image

  • The [%Power Snippets:PSScript%] is a lookup to our Get-WebServiceProxy script snippet. The lookup makes the Get-WebServiceProxy function available to our script. The lookup is something like an old school PHP-include ;-)image
  • The script bellow the lookup generates a proxy for the SharePoint Lists.asmx webservice, call the GetListCollection method, generates from the response an HTML string containing a bullet list.
  • In the next step we set the "Result" column to the "result" variable we filled before with PowerActivity.

image

  • Save and start the workflow...image
  • :-)

Another way to call a web service with the PowerActivity would be to create the proxy with or Visual Studio wsdl.exe, compile and deploy the assembly to the global assembly cache of the server. Now you can load the assembly in PowerShell like [System.Reflection.Assembly]::Load... and instantiate the proxy New-Object -TypeName... This solution is faster and you don't need the WinSDK on the server.

Any questions?

Bye,Christian

11 comments:

Hosty said...
This comment has been removed by a blog administrator.
Christian said...

I found a better script for using WebServices with PowerShell:
http://poshcode.org/538 (bye Oisin Grehan)

Elune said...

Great materials, thanks!
Original web design

Paul said...

great info thanks for this
Link Building Service

Web 2.0 Design said...

Awesome stuff....
PHP Web Development

cisto said...
This comment has been removed by the author.
cisto said...

Such a refreshing article to read. Thanks for posting.

Short Sale

directory submission service said...

Really cool post, highly informative and professionally written..Good Job.

charity donations said...

Useful info. Hope to see more good posts in the future.

charitable giving said...

Great work buddy, keep it up

article submission service said...

Thank you for this blog.