webservice错误 郁闷 急!

Sucre_Faith 2009-01-15 10:18:59

using System;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;

/// <summary>
///GetProducts 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService()]
//若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
// [System.Web.Script.Services.ScriptService]
public class GetProducts : System.Web.Services.WebService {

public GetProducts () {

//如果使用设计的组件,请取消注释以下行
//InitializeComponent();
}

[WebMethod]
public string[] GetProductList(string prefixText ,int count)
{
Product p = new Product();
SqlDataAdapter da = p.GetProduct();
DataSet ds = new DataSet();
da.Fill(ds);
int j = 0;
int sum = ds.Tables[0].Rows.Count;
int length = prefixText.Length;
List<string> products = null;
//string[] products = new string[sum];
for (int i = 0; i < sum; i++)
{
string SortID = ds.Tables[0].Rows[i]["SortID"].ToString();
string Name = ds.Tables[0].Rows[i]["Name"].ToString();
string Brand = ds.Tables[0].Rows[i]["Brand"].ToString();
string Type = ds.Tables[0].Rows[i]["Type"].ToString();
if (SortID.Substring(0, length).ToString() == prefixText || SortID.Substring(0, length).ToString().ToLower() == prefixText)
{
try
{
products.Add(SortID);
j++;
if (j > (count-1))
{
break;
}
}
catch (System.Web.Services.Protocols.SoapException err)
{
string strerr = err.Message + err.Detail.InnerText;
}
}
if (Name.Substring(0, length).ToString() == prefixText || Name.Substring(0, length).ToString().ToLower() == prefixText)
{
try
{
products.Add(Name);
j++;
if (j > (count - 1))
{
break;
}
}
catch (System.Web.Services.Protocols.SoapException err)
{
string strerr = err.Message + err.Detail.InnerText;
}
}
if (Brand.Substring(0, length).ToString() == prefixText || Brand.Substring(0, length).ToString().ToLower() == prefixText)
{
try
{
products.Add(Brand);
j++;
if (j > (count - 1))
{
break;
}
}
catch (System.Web.Services.Protocols.SoapException err)
{
string strerr = err.Message + err.Detail.InnerText;
}
}
if (Type.Substring(0, length).ToString() == prefixText || Type.Substring(0, length).ToString().ToLower() == prefixText)
{
try
{
products.Add(Type);
j++;
if (j > (count - 1))
{
break;
}
}
catch (System.Web.Services.Protocols.SoapException err)
{
string strerr = err.Message + err.Detail.InnerText;
}
}

}
string[] product = products.ToArray();

return product;
}
}





用断点执行到这 products.Add(SortID);
直接出错
HTTP500内部错误
最可能的原因是:
该网站正在进行维护。
该网站有程序错误。

...全文
107 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
Sucre_Faith 2009-01-16
  • 打赏
  • 举报
回复
请问 怎么封装呢
leo_bogard 2009-01-16
  • 打赏
  • 举报
回复
up
conan19771130 2009-01-16
  • 打赏
  • 举报
回复
楼上正确,products=null不可以add
APOLLO_TS 2009-01-16
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 net_xiaojian 的回复:]
List <string> products = null;

改成

List <string> products = new List <string>();

试试.
[/Quote]

应该可以next了!
net_xiaojian 2009-01-15
  • 打赏
  • 举报
回复
提个建议


if (SortID.Substring(0, length).ToString() == prefixText || SortID.Substring(0, length).ToString().ToLower() == prefixText)
{
try
{
products.Add(SortID);
j++;
if (j > (count-1))
{
break;
}
}
catch (System.Web.Services.Protocols.SoapException err)
{
string strerr = err.Message + err.Detail.InnerText;
}
}
if (Name.Substring(0, length).ToString() == prefixText || Name.Substring(0, length).ToString().ToLower() == prefixText)
{
try
{
products.Add(Name);
j++;
if (j > (count - 1))
{
break;
}
}
catch (System.Web.Services.Protocols.SoapException err)
{
string strerr = err.Message + err.Detail.InnerText;
}
}
if (Brand.Substring(0, length).ToString() == prefixText || Brand.Substring(0, length).ToString().ToLower() == prefixText)
{
try
{
products.Add(Brand);
j++;
if (j > (count - 1))
{
break;
}
}
catch (System.Web.Services.Protocols.SoapException err)
{
string strerr = err.Message + err.Detail.InnerText;
}
}
if (Type.Substring(0, length).ToString() == prefixText || Type.Substring(0, length).ToString().ToLower() == prefixText)
{
try
{
products.Add(Type);
j++;
if (j > (count - 1))
{
break;
}
}
catch (System.Web.Services.Protocols.SoapException err)
{
string strerr = err.Message + err.Detail.InnerText;
}
}



这段代码可以封装的.
net_xiaojian 2009-01-15
  • 打赏
  • 举报
回复
List<string> products = null;

改成

List<string> products = new List<string>();

试试.
IMAGSE 2009-01-15
  • 打赏
  • 举报
回复
友情绑定Too
cwmwss 2009-01-15
  • 打赏
  • 举报
回复
友情帮顶!

62,268

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧