我正在尝试使用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
我尝试过多个用户名/密码组合以及根本没有身份验证(因为我没有受到浏览器的质疑)。
有谁能让我知道我错过了什么?
由于
答案 0 :(得分:0)
原来禁用基本授权。不确定为什么那会很重要,因为我甚至尝试过Windows授权(启用了IS),但也没有用。
启用基本授权,现在可以使用。