我希望使用Workday WebService v30.0
我正在尝试复制示例https://community.workday.com/node/191970 我一直得到"无效的用户名和密码"。我知道用户名和密码是正确的,因为它在SOAP UI中有效。
这是我的代码:
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因错误而失败:
Stack Trace是
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
任何想法或指示?谢谢大家。
答案 0 :(得分:4)
我不得不使用CustomBinding和authenticationMode =“UserNameOverTransport”,我不再有身份验证问题。
(如果有人遇到与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>