3

I'm trying to call a .Net (asmx) web service that takes a UTC date and returns the local date.

An input to the web service could look like this: 2015-04-30T23:00:00Z
The output from this call will look like this:

<?xml version="1.0" encoding="UTF-8"?>
<string xmlns="http://tempuri.org/">5/1/2015 12:00:00 AM</string>

I'm new to web services; I want to use the HttpSend activity in my 2013 workflow but apart from Uri, which is obvious, I'm not sure what to put into each of the fields?

enter image description here

The web service code:

namespace spLeaveBooking.WebServices
{
    public class GetLocalTime : WebService
    {
        [WebMethod]
        public string GetLocalTimePlease(string inputDateTime)
        {
            DateTime dateTime = DateTime.Parse(inputDateTime);
            return dateTime.ToLocalTime().ToString();
        }
    }
}
4
+25

Please try following configuration for HttpSend activity:

  1. RequestHeader - Accept:"text/html; charset=utf-8", Content-Type:"text/html; charset=utf-8".
  2. Uri: URL to access the webservice method.Pass the parameter in querystring. eg: string.Format(".../GetLocalTime.asmx/GetLocalTimePlease/{0}",dateTimeVariable)

Or

string.Format(".../GetLocalTime.asmx/GetLocalTimePlease?inputDateTime={0}",dateTimeVariable)
  1. ResponseContent : Specify the workflow variable which will store the data returned from webservice.

Now after the HttpSend action, you will have to parse the webservice response, stored in the workflow variable. For this use GetDynamicValueProperty<T> activity.

Edit: Let's say the webservice returns object of below class:

class ReturnData { public string returnDate{ get; set; } }

Then your Workflow variable, will be an object of class ReturnData , then you will need to to do below configuration to parse it:

PropertyName:"returnDate", Source: Name of the workflow variable which has the webservice response content

Other reference links:

  1. See this solution to know about parsing the dynamic values.
  2. See this code solution for HttpSend Activity calling WCF
  • Unnie, passing of the parameter in the query string is what I'm confused about at the moment. So as mentioned in my question, the parameter that is passed is a string that looks like 2015-04-30T23:00:00Z. You have suggested to use string.Format, but I don't see any array parameters e.g. {0}? If I wanted to send a hard coded parameter, would the query string look like this: string.Format(".../GetLocalTime.asmx/GetLocalTimePlease/2015-04-30T23:00:00Z")? – Submits Jun 15 '15 at 10:02
  • Thanks for finding it. i missed the {0} during typing. Yes the hardcoded parameter passed is correct, but you can remove the string.format in that case – Unnie Jun 15 '15 at 11:35
  • Should this URL with the hard coded parameter also work in the browser? Because it does not. I see a SharePoint error that simply says "Sorry, something went wrong". The URL to ".../GetLocalTime.asmx" works though - I see the web service page where I can select the "GetLocalTime" operation. Also, what would the URL look like if I needed to send two (or more) parameters to the web service? Thanks for your help. – Submits Jun 15 '15 at 11:40
  • So I now have this error message in my workflow with the hard coded parameter: An unhandled exception occurred during the execution of the workflow instance. Exception details: System.IO.InvalidDataException: Unable to deserialize HTTP response content. Expected ContentType : 'application/json', 'text/plain' or 'text/html', Received ContentType : 'text/html'. Content (truncated) : ''. ResponseStatusCode : 'OK' Request Uri : 'siteurl/GetLocalTime.asmx/GetLocalTimePlease/…' – Submits Jun 15 '15 at 12:05
  • I think you will have to change the RequestHeader property to text/html instead of text/xml. – Unnie Jun 15 '15 at 12:46
3

Put a dynamic value variable in the response content box and put this in the RequestHeader box:

enter image description here

Then after the HttpSend activity add a GetDynamicValue activity in which you extract the values you need:

enter image description here

  • A few questions for you: 1. Do I use the CreateDynamicValue activity first? 2. In this activity do I assign just any random string to the PropertyName property? Or does it need to be the same variable name as defined in the input parameters to the web service? 3. With the GetDynamicValue activity, should the Source property be set to the HttpSend activity's ResponseContent property? 4. In the GetDynamicValue activity, what should go in the Path column? The web service just returns a string. I have updated my question with the web service code. – Submits May 5 '15 at 9:45
  • Any help with my questions @tomvanderhoek? – Submits May 6 '15 at 10:02
  • Will look into when i am at home :) – tomvanderhoek May 6 '15 at 10:27
  • could really use your help, I can't get HttpSend to work :( – Submits May 7 '15 at 13:57
  • (1) No, I simply create a DynamicValue variable in the list of variables. (2) Which PropertyName property? (3) Yes definately (4) The response is JSON format, in your path should be one of the column from the response. If you want to view your resonse text try the same HttpRequest in POSTMAN in Chrome :). – tomvanderhoek May 7 '15 at 20:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.