0
我試圖從使用asp.net的SharePoint Foundation 2010中使用Web服務。訪問網絡服務時出現401錯誤
我得到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
我已經試過幾個用戶名/密碼組合以及完全沒有認證(因爲我不是從瀏覽器的挑戰)。
任何人都可以給我一個想法,我失蹤了嗎?
謝謝