Dec 23, 2008

iLSP - SharePoint Designer “Call a Web Service” Action

“iLSP” – is the abbreviation for iLove SharePoint.

The “Call a WebService” workflow action is included in the iLSP -SharePoint Designer Actions 1.0 release. Installation see readme.txt.

The action supports SOAP 1.1, SOAP 1.2, basic and windows authentication.

Let’s go and call a built-in SharePoint web service – Lists.asmx and create a new List with the AddList operation.

  • Bring up SharePoint Designer and create a new workflow on an list with a “Title” and “Response” (Multiple lines of text – plain text) column.
  • Add the “Call a Web Service” action from the “iLove SharePoint” category

image

  • Configure the action as follows:
    • URL: http://[siteurl]/_vti_bin/Lists.asmx
    • SOAP Version: SOAP 1.2
    • SOAPAction: not needed for SOAP 1.2
    • Envelope:

<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<AddList xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<listName>[%MyList:Title%]</listName>
<description>Created by iLSP action</description>
<templateID>100</templateID>
</AddList>
</soap12:Body>
</soap12:Envelope>

You can copy the SOAP 1.2 example request from http://[siteurl]/_vti_bin/Lists.asmx?op=AddList

      • For the <listName> insert a reference to the current item’s title.

image

      • As <description> enter “Created by iLSP action
      • Set the <templateID> to 100” = custom list

  • Response: create a new string workflow variable named “response” and assign it. The action will fill the variable with the response from web service call (xml string).
  • User: leave empty. Empty user = use default credentials.
  • Password: leave empty

Now the “Call a WebService” action is configured.

To check the response, we will write it in the “Response” column of the item using the built-in “Set field in current item” action. Set field to “Response” and “Value” to the above defined workflow variable “response”

image

Try it – Start the workflow on an item

The response:

image

The new list:

image

Because the raw response isn’t very useful, we now parse it using iLSP “Query XML” action. Place the action between the “Call a WebService” and the “Set field in current item” action.

  • Add the “Query XML” action to the workflow

image

  • Configure the “Query XML” action
    • Input: choose the above defined workflow variable “response
    • XPath: //*[local-name()='List']/@ID
      • You can use any valid XPath expression e.g. count(//*). Is the expression result is a single node it will write the node’s inner XML to the result variable. Is the result a node collection, it will merge all the node’s inner XML separated by an semicolon into the result variable. You should identify the node by the local name, because you can’t use xml namespaces.
    • Result: Create a new string workflow variable named “ListID” and assign it.

The “Query XML” action is now configured

Now modify the “Set field in current item” action so that the response column is set to the ListID variable.

image

Start the workflow again

Result:

image

THE END

iLove SharePoint – SharePoint Designer Actions 1.0

I’ve just uploaded some SharePoint Designer Actions (beta) to my CodePlex project iLove SharePoint.

Included Actions

  • Call a WebService (supports SOAP 1.1 and SOAP 1.2)
  • Query XML
  • Execute SQL (supports ADO Provider Model, returns a scalar value)
  • Get parent folder (returns the ID of the folder)
  • Create a site
  • Start workflow
  • Set role inheritance of an item
  • Clear role assignments of an item
  • Assign role to an item

...other useful Actions can be found under: http://www.codeplex.com/SPDActivities

At the moment the actions aren't well tested. Any feedback would be appreciated.
I'm going to write some blog posts how to use them soon...

Bye, Christian

Dec 22, 2008

Call WCF Services With PowerShell

Call WCF Services with PowerShell using any binding. Generates proxies on the fly without any tool expect .NET 3.5. You can also discover the service endpoints, bindings and contracts.
  • The PS2WCF script
 
Example:
Download sample WCF Hello Service project and start ConsoleShell
  • Meatdata discovery:

$wsdl = Get-WsdlImporter -wsdlUrl "net.tcp://localhost:8888/HelloService/mex" $wsdl.ImportAllEndpoints() | format-list

Output:

image

Note: For none mex endpoints use: Get-WsdlImporter -wsdlUrl http://anyurl/service.svc?wsdl –httpGet $true

  • Generate the WCF proxy

$proxyTypes = Get-WcfProxy -wsdlUrl "net.tcp://localhost:8888/HelloService/mex"

or

$proxyTypes = Get-WcfProxy –wsdlImporter $wsdl

$proxyTypes | format-table

Output:

image

  • Call a service operation

$address = New-Object System.ServiceModel.EndpointAddress("net.tcp://localhost:8888/HelloService/")

$binding = new-object System.ServiceModel.NetTcpBinding

$proxy = New-Object $proxyTypes -ArgumentList $binding, $address

$proxy.SayHello("Christian")

or use bindings and addresses generated from WsdlImporter

$endpoints = $wsdl.ImportAllEndpoints()

$proxy = New-Object $proxyTypes($endpoints[0].Binding, $endpoints[0].Address)

$proxy.SayHello("Christian")

Output:

image 

By Christian Glessner

Dec 1, 2008

SharePoint Power Event Receiver 2.0 Released!

New Features in Version 2.0:
  • Security: Only Farm Administrators are permitted to edit scripts
  • The scripts will be included in SharePoint site templates (*.stp)
  • New predefined functions: Get-SPSite, Get-SPWeb, Select-SPListItem
  • Supports editing in PowerGUI (needs iLoveSharePoint PowerGUILauncher)
  • Fixes invalid cast issue with $properties, fixes issue with unregistering item events
Download on my Codeplex Project iLove SharePoint.

Bye, Christian