我正在尝试使用 asp.net 从 SharePoint Foundation 2010 使用 Web 服务。
我收到 401 未经授权的错误。
我知道这意味着凭据丢失或无效,但我似乎无法找出原因。
我无需身份验证即可从标准浏览器访问 Web 服务页面,这对用户/密码没有挑战。这既适用于服务器本身,也适用于远程客户端浏览器。
这是代码:
Dim wsLists As New JEMS30LISTS.Lists
Dim dtTasks As New DataTable
Dim xmlDoc As New System.Xml.XmlDocument
Dim ndQuery, ndViewFields, ndQueryOptions, ndListItems As System.Xml.XmlNode
Dim szListName, szListsUrl, szUsername, szPassword, szDomain As String
szListsUrl = "https://demo.********.com/_vti_bin/Lists.asmx"
szUsername = "*********"
szPassword = "************"
szDomain = "***********"
ndQuery = xmlDoc.CreateNode(System.Xml.XmlNodeType.Element, "Query", "")
ndViewFields = xmlDoc.CreateNode(System.Xml.XmlNodeType.Element, "ViewFields", "")
ndQueryOptions = xmlDoc.CreateNode(System.Xml.XmlNodeType.Element, "QueryOptions", "")
ndQueryOptions.InnerXml = "<IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns>" _
+ "<DateInUtc>TRUE</DateInUtc>"
If bAllFields = True Then
ndViewFields.InnerXml = ""
Else
ndViewFields.InnerXml = "<FieldRef Name=""TEAS_x0020_5_x0020_Task_x0020_Nu"" /> <FieldRef Name=""TEAS_x0020_5_x0020_SubTask"" /> <FieldRef Name=""TEAS_x0020_6_x0020_Task_x0020_Nu"" /> <FieldRef Name=""TEAS_x0020_6_x0020_Task_x0020_Nu0"" /> <FieldRef Name=""Shreds_x0020_Converted"" /> <FieldRef Name=""TEAS_x0020_6_x0020_Shred_x0020_P"" /> <FieldRef Name=""ProcessTask"" /> <FieldRef Name=""TEAS6Dept"" /> "
End If
ndQuery.InnerXml = "<OrderBy><FieldRef Name=""TEAS_x0020_5_x0020_Task_x0020_Nu"" Ascending=""True""></FieldRef></OrderBy>"
szListName = "CORs"
Try
Dim cache As New System.Net.CredentialCache
wsLists.Url = szListsUrl
Dim vUri As New Uri(wsLists.Url)
Dim vNW As New Net.NetworkCredential()
cache.Add(vUri, "windows", vNW)
wsLists.Credentials = cache
ndListItems = wsLists.GetListItems(szListName, Nothing, ndQuery, ndViewFields, 99999, ndQueryOptions, Nothing)
Catch ex As Exception
Response.Write("GetListItems: " + ex.Message + "<br>")
End Try
我已经尝试了几个用户名/密码组合以及根本没有身份验证(因为我没有受到浏览器的挑战)。
谁能告诉我我错过了什么?
谢谢