When using Nintex Workflow, one of the great functional aspects is the ability to call out to a web service – where you can do pretty much whatever you like.
I’ve done this a bunch of times – call to a web method with some C# code – which can then format results, or read/write to another system or do whatever the workflow requires.
The configuration of the “call” to the web service constructs a SOAP packet under the covers, and then executes it. This means that the data values have also have to align with the “XML” schema/definition.
I’ve been having some troubles with calling to a specific web service – and this turned out to be due to the SOAP packet – or more specifically, the data being passed to the web service.
Consider the following example…. (explanation – and answer – to follow)
Web Service method
This code writes a message to the EventLog within the local SharePoint server – not really the best example – as this will only write to the Event Log for the server that the WF is running on – ie. if multiple servers (WFE’s, load balanced, etc) – but it serves as an example of the web service functionality.
public class Logger : System.Web.Services.WebService
public void WriteToEventLog(string workflowName, string messageText)
string log = "Application";
EventLog.WriteEntry(workflowName, messageText, EventLogEntryType.Error);
SharePoint Site + List
As part of the fictitious ‘Wonky Bikes’ corporation, there is a new SharePoint list for the ‘company register’.
This allows people to add a list item with the details for a company – and then the above web service is called from the workflow.
(as stated – this is not a great example, but it serves the purpose to explain the solution and application architecture, etc).
- List Name : Company Register
- Columns : Title, Contact Person, Company Address
This WF will call to this Web Service – and log that a new list item (company) has been added.
- Add an action : Call web service
- Enter the web service ‘address’
- Enter the user name & password – NB. should use Workflow Constants for these…(!)
- Hard code the value for the ‘”Workflow” parameter
- Use the value from the list item “Title”
- Insert reference > List Item Properties > Title
The workflow action should look something like this :
Just need to do the following – and then we can try it out :
- Check the workflow settings – to start on new item
- Click Save
- Set the name of the workflow : Company Register Logger
- Click Publish
Try it out !
Just need to go to the SharePoint list – and click “Add New Item”.
Enter the details – and click Save
Here’s an example :
Check if it’s working
If we jump across to the Event Log, we can see that the “Barry’s Bikes” entry was added to the Event Log. The Workflow “name” is listed as the Source – and then the text – as per the Company Register ‘Title’ field – neat, eh ?!
Try with a different value
Let’s add another list item to the Company Register – this time, for “Large & Small Bikes”.
Uh-oh – looks like this has caused an error – but why ?!
It’s the same list – and the same workflow.
Here’s the text of the error :
Failed to process response. Error returned from server: The remote server returned an error: (400) Bad Request.
As mentioned earlier, the data being passed to the web service needs to confirm to the SOAP packet definition – and the data value for Title (Large & Small Bikes) – breaks this…!
We can’t avoid having characters like & in the field value (text) – or symbols like > and <.
Thankfully – Nintex have found a way to ensure that this doesn’t occur.
- Jump back into the Workflow definition – Edit Nintex Workflow
- Edit the settings for the call to the web service (click Configure)
- Ensure you TICK the box for ‘Encode inserted tokens’
- It’s not on by default, and too often, I leave it “un-ticked”
- Save the action
- Save the Workflow
- Re-publish the workflow
Play it again, Sam !
Let’s try a workflow on the same list item that had error’ed previously (for “Large & Small Bikes”).
And – it worked this time !
So – after a rather lengthy post – the message is simple :
- If you have XML-breaking values (text) – when calling a web service – make sure you “tick the box”….