我用web服务返回数组,报错远程服务器返回了错误: NotFound,在线等
web服务方法代码
public ArrayList GetSearchData(int userid,DateTime dt1,DateTime dt2)
{
string sql = string.Format("select questions.questionId,questions.customerId,questions.contactName,questions.Tel,questions.cEmail,questions.questionCon,questions.ctime,questions.questionState,questions.gjkstime,questions.quewctime,questions.gjdocid,questions.customerscore,questions.customerpj,quetype.quetype from questions left OUTER join quetype on quetype.typeId=questions.typeId where questions.customerId={0} and questions.ctime between '{1}' and '{2}'", userid, dt1, dt2);
string connstr = ConfigurationManager.ConnectionStrings["ServeCustomers.Properties.Settings.ServeCustomerConnectionString"].ToString();
SqlConnection conn = new SqlConnection(connstr);
conn.Open();
SqlDataAdapter sa = new SqlDataAdapter(sql, conn);
conn.Close();
conn.Dispose();
DataSet ds = new DataSet();
sa.Fill(ds, "SearchData");
ArrayList al = new ArrayList();
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
GetQuestionsinfo gi = new GetQuestionsinfo();
gi.usertel = ds.Tables[0].Rows[i]["Tel"].ToString();
gi.contactname = ds.Tables[0].Rows[i]["contactName"].ToString();
gi.quecontact = ds.Tables[0].Rows[i]["questionCon"].ToString();
string questionid = ds.Tables[0].Rows[i]["questionId"].ToString();
gi.serveid = Convert.ToInt64(questionid);
string customerid = ds.Tables[0].Rows[i]["customerId"].ToString();
gi.userid = Convert.ToInt32(customerid);
gi.useremail=ds.Tables[0].Rows[i]["cEmail"].ToString();
gi.quetype = ds.Tables[0].Rows[i]["quetype"].ToString();
string dt = ds.Tables[0].Rows[i]["ctime"].ToString();
gi.ctime = Convert.ToDateTime(dt);
gi.gjtime = ds.Tables[0].Rows[i]["gjkstime"].ToString();
gi.wctime = ds.Tables[0].Rows[i]["quewctime"].ToString();
gi.customerscore = ds.Tables[0].Rows[i]["customerscore"].ToString();
gi.customerthink = ds.Tables[0].Rows[i]["customerpj"].ToString();
gi.gjdoc = ds.Tables[0].Rows[i]["gjdocid"].ToString();
gi.questate = ds.Tables[0].Rows[i]["questionState"].ToString();
al.Add(gi);
}
ds.Dispose();
sa.Dispose();
return al;
}(单步调试,到这里就报错)
客户端调用方法代码如下:
private void Search_Click(object sender, RoutedEventArgs e)
{
UserManageSoapClient ums = new UserManageSoapClient();
ums.GetSearchDataCompleted += new EventHandler<GetSearchDataCompletedEventArgs>(ums_GetSearchDataCompleted);
DateTime dt1=Convert.ToDateTime("2011/12/23 10:13:32");
DateTime dt2 = Convert.ToDateTime("2011/12/23 10:15:39");
ums.GetSearchDataAsync(1,dt1,dt2);
}
void ums_GetSearchDataCompleted(object sender,GetSearchDataCompletedEventArgs e)
{
if (e.Error != null)
{
MessageBox.Show(e.Error.ToString());
return;
}
if (e.Result == null)
{
MessageBox.Show("未找到符合条件的数据");
return;
}
this.DataSearch.ItemsSource = e.Result;
}
自定义类:
public class GetQuestionsinfo
{
public long serveid;
public int userid;
public string contactname;
public string usertel;
public string useremail;
public string quetype;
public string quecontact;
public DateTime ctime;
public string gjtime;
public string wctime;
public string customerscore;
public string customerthink;
public string gjdoc;
public string questate;
}
[解决办法]
首先你调试一下,看看是不是没有从数据库中取出数据,排查是否是数据库没有数据。
然后你试试另外写一个测试方法(直接返回字符串),看看能否直接用这个测试方法获取到数据。排查是否是权限等原因造成无法获取数据
[解决办法]
先看看是不是连接所有表都存在这种问题?还是就读取这个表会存在这个问题。
如果就单独读某一表的时候存在这个问题。
通过WCF访问服务器数据。数据传输大小是有限制的。因为返回的数据量过大。
在Web.config中加入以下代码:
<configuration>
.
.
.
<system.serviceModel>
<services>
<service name="项目名.Web.域服务名" behaviorConfiguration="项目名.Web.域服务名"></service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="项目名.Web.域服务名">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
</configuration>
这里有更加详细的设置。你可以试试。
http://www.silverlightchina.net/html/tips/2010/0902/1825.html