如何在 Project Server SOAP API 中进行身份验证?

How to authenticate into Project Server SOAP API?

我正在尝试从 C# 代码执行 soap 操作。 (顺便说一句,它使用非标准 api 在 projectserverservices.dll 中不可用)

通过网络浏览器执行以下操作:

curl 'http://servername/pwa/_vti_bin/PSI/ProjectServer.svc' -H 'AsmxRoutedCall: true' -H 'Origin: http://servername' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: en-US,en;q=0.9,pl;q=0.8' -H 'User-Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36' -H 'Content-Type: text/xml; charset=UTF-8' -H 'Accept: */*' -H 'Referer: http://servername/pwa/Timesheet.aspx?tsUID=06b92bf0-806e-44d5-8c94-616c50471920&Source=http://servername/pwa/_layouts/pwa/timesheet/mytssummary.aspx' -H 'Cookie: ASP.NET_SessionId=kiihu1na3qifbojttxlauu3u; loginAsDifferentAttemptCount=; previousLoggedInAs=; PWA_Perf=0; OfflineClientInstalled=0; Ribbon.ContextualTabs.TiedMode.Home=1639690|-1|436|1720094216; PWA6637f161eb954cdc9bc621ab4641ce27CORPNET+AF8-TEST1=703012DE208D9FAF800770FA89647B17B21C3F5345D974ED344773B4049A0532D0757CD3B9103EEA8B41053A136ED4740A696A746CF5D3C5B272D0E94F935AF541C1EAD826B960CEBF9F63B6AB631A99576BD9DDE240346B12E247D3932E57CF850CD5066C0F360CDC2982E74C71D8727A2F2858B3DC9F0E9BAD53A90E9C3166BAC37B4853057B4ACD426B46AD1AF70E3C42406DAC090113F461529640E3E2EE3012C9339A62798236643998734757A0990F58F0B68483D4B3C0F570EDA809E2EDCA0AFC19333876B493CF6D43ECA43C9B6944D93C0DAAE641D32AAEFBF58DA878887838EE7BD87F9A9CDB0EFA09618EFDEFB7ED7E021A83EE1FB1B679D7D707A18C750AFEE9F63E844CBAB9B73B95389C56E46A2BE67C223A828AD2565966836B868C832F6D37FE35AFAE8D3003EEF2D91DE9A5DCE5C2E41C32AE4CF01A6A1C04A3405AC614089953C25D64CA44E016A7FD9958CB51339AE7BB542C291C5A44DDF61F33520BC62DED70E94FA48F4D157B714C9BFCE97DFC3338E1F6FCBEE8B310F137D612865B34B738087F4586FAFF30F2E15D70CBB96F969354B91B22B0FE11D3B12858B4778DF87F8F52FB4B6B9D0EDF16C6A84D783217EE81D780D59CAF40EE15B8EE2B6D89461C8DA6E7002D04CDA8EABE4C5DA4FEBD199A95A96A2D75F3FA9C14E2FEFE8B6C3D5C5D14D611A29FE5103226C8EDEDDC69A85B526DFEA6DB0EBEDCE8A4790E908C7251F0B7A3A8CEE0496C545AD8C58D77D29ED965A71D3E4227792E153BFE967B7A76EE2C92C86ABCE56D70E36F257C4B743F07CEA0E43F9A3CBC3F367D4257BF070AA654EAA07E182386CBFDBEE02D83C382504F844F15206643F3EAD946B392DBBDD41FFC412FBA06A8950A0D14588FF535B04B02BA0CCC5765F49C34541DCCA674E5DA4B3DBA75BA5CB208D0D7CBA8D7710315A6FD9D5DDDFA6C7D1A893F9FD6DD9DBF66DB545D9E73' -H 'Connection: keep-alive' -H 'SOAPAction: http://schemas.microsoft.com/office/project/server/webservices/PWA/TimeSheetSendGridUpdatesForSave' --data-binary '<?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><TimeSheetSendGridUpdatesForSave xmlns="http://schemas.microsoft.com/office/project/server/webservices/PWA/"><jobUid>{f6880caf-9407-4454-ac60-84a30f57079c}</jobUid><tsUid>{06b92bf0-806e-44d5-8c94-616c50471920}</tsUid><changesJson>[{"updates":[{"type":2,"recordKey":"a81cc5f7-307a-46ce-a131-77e15468c29f","fieldKey":"TPD_col2a","newProp":{"dataValue":"600000","hasDataValue":true}},{"type":2,"recordKey":"a81cc5f7-307a-46ce-a131-77e15468c29f","fieldKey":"TPD_col2t","newProp":{"dataValue":"600000","hasDataValue":true}}],"changeNumber":1},{"updates":[{"type":2,"recordKey":"9f076a35-1394-4c6b-950a-aee4179febdc","fieldKey":"TPD_col2a","newProp":{"dataValue":"600000","hasDataValue":true}}],"changeNumber":2},{"updates":[{"type":2,"recordKey":"9f076a35-1394-4c6b-950a-aee4179febdc","fieldKey":"TPD_col2t","newProp":{"dataValue":"600000","hasDataValue":true}}],"changeNumber":3}]</changesJson><viewOptionsJson>{"dateFormat":3,"workFormat":2,"durationFormat":7,"filterType":5,"loadViewProperties":true,"newTasks":[],"importTasks":[],"removedLines":[]}</viewOptionsJson></TimeSheetSendGridUpdatesForSave></soap:Body></soap:Envelope>' --compressed --insecure

如果我尝试在邮递员中使用它,它只是不起作用(响应 401 未授权)使用 NTLM Auth (beta)

如果我尝试从邮递员生成代码到 C# (RestSharp) - 同样的结果 401

知道我应该如何创建这样的请求吗?

除了魔术库(比如projectserverservices.dll)之外,我可以使用任何技术:)

我已通过从 SOAP UI 进行调用成功验证了用户。 如前所述,我正在执行未记录的调用(没有 WSDL),因此要从 SOAP UI 发出这样的请求,您必须创建空的 REST 项目并向其添加一个 wsdl 端点。 如果这在 SOAP 中可行 UI 那么在 C# 中肯定可行。

端点:http://servername
资源:/pwa/_vti_bin/PSI/ProjectServer.svc

Headers:

AsmxRoutedCall: true
X-FORMS_BASED_AUTH_ACCEPTED: f
User-Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36
SOAPAction: http://schemas.microsoft.com/office/project/server/webservices/PWA/TimeSheetSendGridUpdatesForSave

从 C# 创建这样的调用非常简单。 如果您使用的是 HttpClient,只需使用

httpClient.UseDefaultCredentials = true 
# or
httpclient.Credentials = new NetworkCredentials(username,password,domain)

如果您使用的是 RestSharp,请使用:

client.Authenticator = new NtlmAuthenticator(new NetworkCredential(username,password,domain));