Search code examples
c#web-servicessoapworkday-api

Workday Web Service Authentication with C#


I am looking to use Workday WebService v30.0

https://community.workday.com/sites/default/files/file-hosting/productionapi/Human_Resources/v30.0/Human_Resources.html

I am trying to replicate example https://community.workday.com/node/191970 and I keep getting "invalid username and password". I know that username and password is correct, because it works in SOAP UI.

Here is my code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ServiceModel;

using GetWorkerSample.HumanResources;

namespace GetWorkerSample
{
    class Program
    {
        static void Main(string[] args)
        {
            //Instantiate an instance of WCF generated proxy and set the Endpoint
            Human_ResourcesPortClient hr = new Human_ResourcesPortClient();
            hr.Endpoint.Address = new EndpointAddress(args[0]);


            //Configure Port
            hr.ClientCredentials.UserName.UserName = "user@tenant";
            hr.ClientCredentials.UserName.Password = "password";

            //Instantiate Header for the request
            //Confiure Header
            Workday_Common_HeaderType header = new Workday_Common_HeaderType();
            header.Include_Reference_Descriptors_In_Response = false;
            header.Include_Reference_Descriptors_In_ResponseSpecified = false;


            //Setting up filter to get data for 5 workers
            //Response Filter
            Response_FilterType responseFilter = new Response_FilterType();
            responseFilter.Count = 5;
            responseFilter.Page = 1;
            responseFilter.PageSpecified = true;
            responseFilter.CountSpecified = true;


            //Configure Criteria
            Worker_Request_CriteriaType requestCriteria = new Worker_Request_CriteriaType();
            requestCriteria.Exclude_Inactive_Workers = true;
            requestCriteria.Exclude_Inactive_WorkersSpecified = true;


            // Formating response to contain Personal information, Employment information and Compensation
            //Configure Response Group
            Worker_Response_GroupType responseGroup = new Worker_Response_GroupType();
            responseGroup.Include_Reference = true;
            responseGroup.Include_Personal_Information = true;
            responseGroup.Include_Compensation = true;
            responseGroup.Include_Employment_Information = true;
            responseGroup.Include_ReferenceSpecified = true;
            responseGroup.Include_Personal_InformationSpecified = true;
            responseGroup.Include_CompensationSpecified = true;
            responseGroup.Include_Employment_InformationSpecified = true;
            responseGroup.Include_Organizations = true;
            responseGroup.Include_OrganizationsSpecified = true;

            //updating preferences for the request
            //Configure Request
            Get_Workers_RequestType request = new Get_Workers_RequestType();
            request.Request_Criteria = requestCriteria;
            request.Response_Filter = responseFilter;
            request.Response_Group = responseGroup;
            request.version = "v30.0";

            //Invoke HR getworker api via Proxy
            try
            {
                var Testtworker = hr.Get_Workers(header, request).Response_Data;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            Console.Read();

        }
    }
}

hr.Get_Workers failed with error:

enter image description here

Stack Trace is

Server stack trace: 
   at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]: 
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at GetWorkerSample.HumanResources.Human_ResourcesPort.Get_Workers(Get_WorkersInput request)
   at GetWorkerSample.HumanResources.Human_ResourcesPortClient.GetWorkerSample.HumanResources.Human_ResourcesPort.Get_Workers(Get_WorkersInput request) in C:\temp\Projects\WorkDayProjects\GetWorkerSample\GetWorkerSample\GetWorkerSample\Service References\HumanResources\Reference.cs:line 136983
   at GetWorkerSample.HumanResources.Human_ResourcesPortClient.Get_Workers(Workday_Common_HeaderType Workday_Common_Header, Get_Workers_RequestType Get_Workers_Request) in C:\temp\Projects\WorkDayProjects\GetWorkerSample\GetWorkerSample\GetWorkerSample\Service References\HumanResources\Reference.cs:line 136990
   at GetWorkerSample.Program.Main(String[] args) in C:\temp\Projects\WorkDayProjects\GetWorkerSample\GetWorkerSample\GetWorkerSample\GetWorkerSample.cs:line 93

Any ideas or pointers ? Thanks all.


Solution

  • I had to use CustomBinding with authenticationMode="UserNameOverTransport" and I no longer have authentication issues.

    (Posting this in case anyone encounters same issue with Workday API)

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
        <startup> 
            <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
        </startup>
        <system.serviceModel>
          <bindings>
            <customBinding>
              <binding name="customHRBinding" sendTimeout="00:05:00" receiveTimeout="00:05:00">
                <security enableUnsecuredResponse="true" authenticationMode="UserNameOverTransport" />
                <textMessageEncoding messageVersion="Soap11" />
                <httpsTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
              </binding>
            </customBinding>
          </bindings>
            <client>
                <endpoint address="https://wd2-impl-services1.workday.com/ccx/service/tenant7/Human_Resources/v30.0"
                    binding="customBinding" bindingConfiguration="customHRBinding"
                    contract="HumanResources.Human_ResourcesPort" name="Human_Resources" />
            </client>
        </system.serviceModel>
    </configuration>