我有一个客户正在 Sharepoint 2013 Online 中实施客户门户。当前程序通过邮件向客户分发文件。现在我们必须将文件上传到客户门户。
我尝试在 sharepoint 中使用复制 web 服务。我创建了一个测试项目并将 web 服务添加为 Web 参考,并编写了以下测试代码:
static void Main(string[] args)
{
string baseUrl = "https://mycustomer.sharepoint.com/sites/";
string customer = "customerportalname";
string serviceUrl = "/_vti_bin/copy.asmx";
string destinationDirectory = "/folder/";
string fileName = "uploaded.xml";
string username = "username@outlook.com";
string password = "password";
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.LoadXml("<fiets><onderdeel>voorwiel</onderdeel><onderdeel>achterwiel</onderdeel><onderdeel>trappers</onderdeel><onderdeel>stuur</onderdeel><onderdeel>frame</onderdeel></fiets>");
byte[] xmlByteArray;
using (MemoryStream memoryStream = new MemoryStream())
{
xmlDocument.Save(memoryStream);
xmlByteArray = memoryStream.ToArray();
}
string destinationUrl = string.Format("{0}{1}{2}{3}", baseUrl, customer, destinationDirectory, fileName);
string[] destinationUrlArray = new string[] { destinationUrl };
FieldInformation fieldInfo = new FieldInformation();
FieldInformation[] fields = { fieldInfo };
CopyResult[] resultsArray;
using (Copy copyService = new Copy())
{
copyService.PreAuthenticate = true;
copyService.Credentials = new NetworkCredential(username, password);
copyService.Url = string.Format("{0}{1}", baseUrl, serviceUrl);
copyService.Timeout = 600000;
uint documentId = copyService.CopyIntoItems(destinationUrl , destinationUrlArray, fields, xmlByteArray, out resultsArray);
}
}
当我执行代码时,我收到以下错误:
The request failed with the error message:
--
<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href="/_forms/default.aspx?ReturnUrl=%2f_vti_bin%2fcopy.asmx">here</a>.</h2>
</body></html>
--
看起来我没有通过身份验证并被重定向。然而,凭据是正确的。有人有想法吗?提前致谢!
更新
为了能够连接到 SharePoint 2013 Online,您必须附加 Office 365 身份验证 cookie,如本文所述。然而,我的问题是还涉及到 ADFS。如何针对 ADFS 进行身份验证?