1

我几乎制作了一个 API 来使用 Sharepoint Web 服务,除了删除项目部分外,一切正常。

我正在使用 Lists.asmx Web 服务,并且正在调用 UpdateListItems 方法。

我的请求如下所示:

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<UpdateListItems xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<listName>Shared Documents</listName>
<updates><Batch OnError="Continue" ListVersion="1" ><Method ID='1' Cmd='Delete'><Field Name='ID'>99</Field></Method></Batch></updates>
</UpdateListItems>
</soap12:Body>
</soap12:Envelope>

并且响应显示以下错误:

<soap:Reason>
<soap:Text xml:lang="en">Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown
</soap:Text></soap:Reason>
<detail>
<errorstring xmlns="http://schemas.microsoft.com/sharepoint/soap/">The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again.</errorstring>
<errorcode xmlns="http://schemas.microsoft.com/sharepoint/soap/">0x8102006d</errorcode>

任何想法我该如何解决这个问题?

4

1 回答 1

2

经过大量测试和谷歌搜索,我发现这个错误是从创建、更新或删除的 Web 服务中收到的。错误显示是因为在头文件中我没有包含 SOAPAction。

您可以在我找到解决方案的博客上查看详细信息

http://weblogs.asp.net/jan/archive/2009/05/25/quot-the-security-validation-for-this-page-is-invalid-quot-when-calling-the-sharepoint-web-服务.aspx

更改请求以包含以下代码后,安全错误消失了。

NSString *soapAction = [NSString stringWithFormat:@"http://schemas.microsoft.com/sharepoint/soap/%@", method];

    [theRequest addValue:serverName forHTTPHeaderField:@"Host"];
    [theRequest addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    [theRequest addValue:msgLength forHTTPHeaderField:@"Content-Lenght"];
    [theRequest addValue:soapAction forHTTPHeaderField:@"SOAPAction"];
    [theRequest setHTTPMethod:@"POST"];

我希望这个答案会对某人有所帮助。

于 2013-04-15T11:46:09.847 回答