2013-04-12 62 views
1

我幾乎製作了一個API來使用Sharepoint Web Services,除了刪除項目部分外,其他所有工作都正常。Sharepoint Web Service在iPad App中使用時返回錯誤

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

任何想法我怎麼能解決這個問題?

回答

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

我希望這個答案能幫助別人。

相關問題