先免责声明
使用风险自负。此代码不可移植,这意味着 Microsoft 没有义务通知您其内部 Web 服务中的某些更改。
工作解决方案
尝试使用 PWA Timesheet Control 使用的相同 web 服务问题是它没有记录。我们可以调用 TimeSheetSendGridUpdatesForSave Action on /pwa/_vti_bin/PSI/ProjectServer.svc
。
如何?
首先,您必须在标准 dll 之外针对 PSI 进行身份验证。我自己描述和解决的问题在这里
然后你需要用数据调用 web 服务。例如,我们将使用此请求,它将我的任务的实际小时数更改为 12 小时。http://servername/pwa/Timesheet.aspx?tsUID=06b92bf0-806e-44d5-8c94-616c50471920
当您更改时间并在实际 PWA 时间表客户端(在浏览器中)上单击保存时,以下代码段是从 Chrome DevTools ->“网络”选项卡复制的
<?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>{ba875aee-a59f-4c8f-974e-cd5f21dff7b6}</jobUid>
<tsUid>{06b92bf0-806e-44d5-8c94-616c50471920}</tsUid>
<changesJson>[
{
"updates": [
{
"type": 2,
"recordKey": "a81cc5f7-307a-46ce-a131-77e15468c29f",
"fieldKey": "TPD_col2a",
"newProp": { "dataValue": "720000", "hasDataValue": true }
},
{
"type": 2,
"recordKey": "a81cc5f7-307a-46ce-a131-77e15468c29f",
"fieldKey": "TPD_col2t",
"newProp": { "dataValue": "720000", "hasDataValue": true }
}
],
"changeNumber": 20
}
]
</changesJson>
<viewOptionsJson>{"dateFormat":3,"workFormat":2,"durationFormat":7,"filterType":5,"loadViewProperties":false,"newTasks":[],"importTasks":[],"removedLines":[]}</viewOptionsJson>
</TimeSheetSendGridUpdatesForSave>
</soap:Body>
</soap:Envelope>
在 Auth 选项卡中的 SOAP UI 中,您必须以拥有 timesheet 的用户身份提供您的凭据。您不能只从管理员帐户发出请求,因为 PSI 将返回
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<s:Fault>
<faultcode>s:Server</faultcode>
<faultstring xml:lang="pl-PL">ProjectServerError(s) LastError=GeneralInvalidOperation Instructions: Pass this into PSClientError constructor to access all error information</faultstring>
<detail>
<errinfo>
<general>
<class name="Nie można wprowadzić zmian w grafiku. Grafik nie został przesłany lub został odwołany.">
<error id="20011" name="GeneralInvalidOperation" uid="36ec16f4-db82-4fee-8922-2cd8d4084829"/>
</class>
</general>
</errinfo>
</detail>
</s:Fault>
</s:Body>
</s:Envelope>
这就像在下面的 gif 中一样
更新 27.08.2019
调用代码:
[TestMethod]
public void SampleChangeHoursInPlainDotNetWebClient()
{
var httpClient = new WebClient();
httpClient.UseDefaultCredentials = true; // you have to be in a timesheets user scope (windows auth, ntlm)
httpClient.Headers.Add("SOAPAction", "http://schemas.microsoft.com/office/project/server/webservices/PWA/TimeSheetSendGridUpdatesForSave");
httpClient.Headers.Add("Content-Type", "text/xml; charset=UTF-8");
httpClient.Headers.Add("Accept-Language", "en-US,en;q=0.9,pl;q=0.8");
httpClient.Headers.Add("Accept-Encoding", "gzip, deflate");
httpClient.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f");
httpClient.Headers.Add("AsmxRoutedCall", "true");
httpClient.Headers.Add("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");
var data = "<?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>{ad8bd458-564c-49c5-8955-dfa577556d4a}</jobUid><tsUid>{6856cac1-7c88-4020-bdb5-c4e1b1a54b85}</tsUid><changesJson>[{\"updates\":[{\"type\":2,\"recordKey\":\"f88b5297-1985-4c2c-8717-554167471e81\",\"fieldKey\":\"TPD_col0a\",\"newProp\":{\"dataValue\":\"300000\",\"hasDataValue\":true}},{\"type\":2,\"recordKey\":\"f88b5297-1985-4c2c-8717-554167471e81\",\"fieldKey\":\"TS_LINE_STATUS\",\"newProp\":{\"dataValue\":\"0\",\"hasDataValue\":true,\"localizedValue\":\"Nieprzes%u0142ane\",\"hasLocalizedValue\":true}},{\"type\":2,\"recordKey\":\"f88b5297-1985-4c2c-8717-554167471e81\",\"fieldKey\":\"TPD_col0t\",\"newProp\":{\"dataValue\":\"300000\",\"hasDataValue\":true}}],\"changeNumber\":2},]</changesJson><viewOptionsJson>{\"dateFormat\":3,\"workFormat\":2,\"durationFormat\":7,\"filterType\":5,\"loadViewProperties\":true,\"newTasks\":[],\"importTasks\":[],\"removedLines\":[]}</viewOptionsJson></TimeSheetSendGridUpdatesForSave></soap:Body></soap:Envelope>";
var response = httpClient.UploadString("http://preprod2010/pwa/_vti_bin/PSI/ProjectServer.svc", "POST", data);
}
使用 RestSharp:
[TestMethod]
public void SampleChangeHours()
{
var client = new RestClient("http://preprod2010/pwa/_vti_bin/PSI/ProjectServer.svc");
var request = new RestRequest(Method.POST);
request.AddHeader("cache-control", "no-cache");
client.Authenticator = new NtlmAuthenticator(new NetworkCredential("test1","Start123!@#","CORPNET"));
request.AddHeader("Host", "preprod2010");
request.AddHeader("SOAPAction", "http://schemas.microsoft.com/office/project/server/webservices/PWA/TimeSheetSendGridUpdatesForSave");
request.AddHeader("Connection", "keep-alive");
request.AddHeader("Content-Type", "text/xml; charset=UTF-8");
request.AddHeader("Accept-Language", "en-US,en;q=0.9,pl;q=0.8");
request.AddHeader("Accept-Encoding", "gzip, deflate");
request.AddHeader("X-FORMS_BASED_AUTH_ACCEPTED", "f");
request.AddHeader("AsmxRoutedCall", "true");
request.AddHeader("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");
request.AddParameter("undefined", "<?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>{ad8bd458-564c-49c5-8955-dfa577556d4a}</jobUid><tsUid>{6856cac1-7c88-4020-bdb5-c4e1b1a54b85}</tsUid><changesJson>[{\"updates\":[{\"type\":2,\"recordKey\":\"f88b5297-1985-4c2c-8717-554167471e81\",\"fieldKey\":\"TPD_col0a\",\"newProp\":{\"dataValue\":\"300000\",\"hasDataValue\":true}},{\"type\":2,\"recordKey\":\"f88b5297-1985-4c2c-8717-554167471e81\",\"fieldKey\":\"TS_LINE_STATUS\",\"newProp\":{\"dataValue\":\"0\",\"hasDataValue\":true,\"localizedValue\":\"Nieprzes%u0142ane\",\"hasLocalizedValue\":true}},{\"type\":2,\"recordKey\":\"f88b5297-1985-4c2c-8717-554167471e81\",\"fieldKey\":\"TPD_col0t\",\"newProp\":{\"dataValue\":\"300000\",\"hasDataValue\":true}}],\"changeNumber\":2},]</changesJson><viewOptionsJson>{\"dateFormat\":3,\"workFormat\":2,\"durationFormat\":7,\"filterType\":5,\"loadViewProperties\":true,\"newTasks\":[],\"importTasks\":[],\"removedLines\":[]}</viewOptionsJson></TimeSheetSendGridUpdatesForSave></soap:Body></soap:Envelope>", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
}