Metodij Zdravkin
Metodij Zdravkin

Reputation: 924

Sharepoint Web Service returns error when used in iPad App

I pretty much made an API to consume Sharepoint Web Services and everything is working OK except for Delete Item part.

I am using Lists.asmx web service, and am calling method UpdateListItems.

My Request looks like this:

<?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>

And the response shows the following error:

<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>

Any ideas how can I solve this?

Upvotes: 1

Views: 790

Answers (1)

Metodij Zdravkin
Metodij Zdravkin

Reputation: 924

After a lot of testing and googling, I found that this error is received from web services that create, update or delete. The error shows because in the header file I didn't include SOAPAction.

You can check the details on the blog where I find the solution

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

After changing the request to include following code the security error was gone.

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"];

I hope that this answer will help somebody.

Upvotes: 2

Related Questions