我遇到以下错误:
The request failed with HTTP status 401: Unauthorized.
编码
代码如下:
protected void Execute_Click(object sender, EventArgs e)
{
/*Declare and initialize a variable for the Lists Web service.*/
//Web_Reference.Lists myservice = new Web_Reference.Lists();
ListsWebService.Lists myservice = new ListsWebService.Lists();
/*Authenticate the current user by passing their default
credentials to the Web service from the system credential
cache. */
myservice.Credentials =
System.Net.CredentialCache.DefaultCredentials;
/*Set the Url property of the service for the path to a subsite. Not setting this property will return the lists in the root Web site.*/
//listService.Url = "http://Server_Name/Subsite_Name/_vti_bin/Lists.asmx";
myservice.Url = "http://teamsites.ntu.edu.sg/sce/hrdev/_vti_bin/Lists.asmx";
try
{
/*Declare an XmlNode object and initialize it with the XML
response from the GetListCollection method. */
System.Xml.XmlNode node = myservice.GetListCollection();
/*Loop through XML response and parse out the value of the
Title attribute for each list. */
foreach (System.Xml.XmlNode xmlnode in node)
{
Label1.Text += xmlnode.Attributes["Title"].Value + "\n";
}
}
catch (Exception excep)
{
Label1.Text = excep.Message;
}
}
IIS 设置- 仅启用 Windows 身份验证。
Web.Config 文件
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=bxxxxxxxx9" >
<section name="ReadSharePointList.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=bxxxxxxxx9" requirePermission="false" />
</sectionGroup>
</configSections>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<customErrors mode="Off"/>
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="ListsSoap" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://mainsite/subsite/_vti_bin/lists.asmx"
binding="basicHttpBinding" bindingConfiguration="ListsSoap"
contract="StaffRole.ListsSoap" name="ListsSoap" />
</client>
</system.serviceModel>
<applicationSettings>
<ReadSharePointList.Properties.Settings>
<setting name="ReadSharePointList_ListsWebService_Lists" serializeAs="String">
<value>http://mainsite/subsite/_vti_bin/lists.asmx</value>
</setting>
</ReadSharePointList.Properties.Settings>
</applicationSettings>
</configuration>
我会在哪里失踪?