C# 服务器无法处理请求---&燃气轮机;请求失败,HTTP状态为401:未经授权
我有一个web服务,我编写它是为了向sharepoint列表添加值 我可以在本地计算机上调用webservice。但当我将其部署到服务器时,我会得到401状态:未经授权 有人能告诉我为什么我会出现401代理错误吗?我试图在web配置中添加代理标记,但它不起作用 代码C# 服务器无法处理请求---&燃气轮机;请求失败,HTTP状态为401:未经授权,c#,asp.net,.net,web-services,asmx,C#,Asp.net,.net,Web Services,Asmx,我有一个web服务,我编写它是为了向sharepoint列表添加值 我可以在本地计算机上调用webservice。但当我将其部署到服务器时,我会得到401状态:未经授权 有人能告诉我为什么我会出现401代理错误吗?我试图在web配置中添加代理标记,但它不起作用 代码 [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [Syst
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class Req : System.Web.Services.WebService
{
[WebMethod]
public Guid Add()
{
string uniqueGuid = string.Empty;
string[] uniqueID;
try
{
CrmList.Lists list = new CrmList.Lists();
list.PreAuthenticate = true;
#region getvalue
list.Credentials = System.Net.CredentialCache.DefaultCredentials;
XmlNode ndLists = list.GetListCollection();
//XmlNode test = list.GetList(listName);
list.Url = "http://site/_vti_bin/Lists.asmx";
System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
string listName = Properties.Settings.Default.ListGuid;
string viewName = Properties.Settings.Default.ViewGuid;
string rowLimit = Properties.Settings.Default.RowLimit;
System.Xml.XmlElement query = xmlDoc.CreateElement("Query");
System.Xml.XmlElement viewFields =
xmlDoc.CreateElement("ViewFields");
System.Xml.XmlElement queryOptions =
xmlDoc.CreateElement("QueryOptions");
query.InnerXml = "<OrderBy><FieldRef Name='ID' Ascending='False' /></OrderBy>";
viewFields.InnerXml = @"<FieldRef Name='ID' />";
queryOptions.InnerXml = "";
System.Xml.XmlNode nodeListItems = list.GetListItems(listName, viewName, query, viewFields, rowLimit, queryOptions, "09bdac52-8897-41ee-8a0e-df5fdba617e9");
#endregion
string listdata=string.Empty;
string InvoiceType =string.Empty;
listdata= @"<Method ID=""1"" Cmd=""New"">";
listdata += @"<Field Name=""ID""></Field>";
listdata += @"</Method>";
System.Xml.XmlDocument xdoc = new System.Xml.XmlDocument() ;
System.Xml.XmlElement xbatch = xdoc.CreateElement("Batch");
xbatch.SetAttribute("OnError", "Return");
xbatch.InnerXml = listdata;
try
{
list.UpdateListItems(listName, xbatch);
}
catch (Exception ex)
{
}
#region getguid
System.Xml.XmlNode currentListValues = list.GetListItems(listName, viewName, query, viewFields, rowLimit, queryOptions,Properties.Settings.Default.WebGuid);
string test = string.Empty;
XmlDocument xdoc1 = new XmlDocument();
XmlNamespaceManager nsmanager = new XmlNamespaceManager(xdoc1.NameTable);
nsmanager.AddNamespace("ns1", "http://schemas.microsoft.com/sharepoint/soap");
xdoc1.LoadXml(currentListValues.InnerXml);
System.Xml.XmlElement root = xdoc1.DocumentElement;
List<string> str1 = new List<string>();
XmlAttributeCollection attCol;
bool IsGuid;
foreach (System.Xml.XmlNode listItem in root)
{
string name = listItem.Name;
string value = listItem.OuterXml;
attCol = listItem.Attributes;
for (int i = 0; i < attCol.Count; i++)
{
IsGuid = attCol[i].Value.ToString().Contains("{");
if (IsGuid)
{
uniqueID = attCol[i].Value.ToString().Split('{');
uniqueGuid = uniqueID[1].ToString().Replace("}", "");
//str1.Add(uniqueGuid);
break;
}
}
if (!string.IsNullOrEmpty(uniqueGuid))
{
break;
}
}
#endregion
}
catch (Exception exc)
{
throw ;
}
Guid currentItemGuid = new Guid(uniqueGuid);
return currentItemGuid;
}
}
[WebService(命名空间=”http://tempuri.org/")]
[WebServiceBinding(ConformsTo=WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
公共类请求:System.Web.Services.WebService
{
[网络方法]
公共Guid添加()
{
string uniqueGuid=string.Empty;
字符串[]唯一;
尝试
{
CrmList.Lists list=新的CrmList.Lists();
list.PreAuthenticate=true;
#区域getvalue
list.Credentials=System.Net.CredentialCache.DefaultCredentials;
XmlNode ndLists=list.GetListCollection();
//XmlNode test=list.GetList(listName);
list.Url=”http://site/_vti_bin/Lists.asmx";
System.Xml.XmlDocument xmlDoc=new System.Xml.XmlDocument();
字符串listName=Properties.Settings.Default.ListGuid;
字符串viewName=Properties.Settings.Default.ViewGuid;
字符串rowLimit=Properties.Settings.Default.rowLimit;
System.Xml.xmlement query=xmlDoc.CreateElement(“查询”);
System.Xml.xmlement视图字段=
CreateElement(“视图字段”);
System.Xml.xmlement查询选项=
CreateElement(“查询选项”);
query.InnerXml=“”;
viewFields.InnerXml=@”;
queryOptions.InnerXml=“”;
System.Xml.XmlNode nodeListItems=list.GetListItems(列表名、视图名、查询、视图字段、行限制、查询选项,“09bdac52-8897-41ee-8a0e-df5fdba617e9”);
#端区
string listdata=string.Empty;
string InvoiceType=string.Empty;
listdata=@;
listdata+=@;
listdata+=@;
System.Xml.XmlDocument xdoc=new System.Xml.XmlDocument();
System.Xml.xmlement xbatch=xdoc.CreateElement(“批处理”);
SetAttribute(“OnError”、“Return”);
xbatch.InnerXml=listdata;
尝试
{
列表。更新列表(列表名,xbatch);
}
捕获(例外情况除外)
{
}
#区域getguid
System.Xml.XmlNode currentListValues=list.GetListItems(listName、viewName、查询、viewFields、rowLimit、queryOptions、Properties.Settings.Default.WebGuid);
string test=string.Empty;
XmlDocument xdoc1=新的XmlDocument();
XmlNamespaceManager nsmanager=新的XmlNamespaceManager(xdoc1.NameTable);
nsmanager.AddNamespace(“ns1”http://schemas.microsoft.com/sharepoint/soap");
xdoc1.LoadXml(currentListValues.InnerXml);
System.Xml.xmlement root=xdoc1.DocumentElement;
List str1=新列表();
XmlAttributeCollection attCol;
bool-IsGuid;
foreach(root中的System.Xml.XmlNode listItem)
{
字符串名称=listItem.name;
字符串值=listItem.OuterXml;
attCol=listItem.Attributes;
for(int i=0;i
您需要使用有效的凭据。默认凭据在您的计算机上工作,因为sharepoint知道用户。如果sharepoint位于另一台计算机上,您需要使用sharepoint服务器上有效的用户和密码创建NetwordCredentials