代码之家  ›  专栏  ›  技术社区  ›  Metodij Zdravkin

Sharepoint Web Service在iPad应用程序中使用时返回错误

  •  1
  • Metodij Zdravkin  · 技术社区  · 12 年前

    我几乎制作了一个API来使用Sharepoint Web Services,除了Delete Item部分之外,其他一切都正常。

    我正在使用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>
    

    有什么想法我该怎么解决吗?

    1 回复  |  直到 12 年前
        1
  •  2
  •   Metodij Zdravkin    12 年前

    经过大量的测试和谷歌搜索,我发现这个错误是从创建、更新或删除的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-services.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"];
    

    我希望这个答案能帮助到一些人。