我使用WCF进行简单的服务器/客户端设置。我的问题是,由于意外关闭的连接服务器
,任何期望返回值的方法都会在异常中产生Conifguration file on server side
Configuratoin file on client side
所有数据类都位于MSO.ErrorSystem.Shared.Datatypes
内的外部项目中
调用方法的代码:
using (var client = Util.GetSearchServiceClient())
{
ViewBag.Results = client.SearchReports(searchTerm, page, 50);
}
Util.GetSearchServiceClient()
:
public static SearchServiceClient GetSearchServiceClient()
{
SearchServiceClient client = new SearchServiceClient();
client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
return client;
}
在服务器端调用的方法:
public IEnumerable<Shared.Datatypes.Report> SearchReports(string pSearchterm, int pPageNum, int pPageSize)
{
using (var session = DatabaseManager.Instance.DocumentStore.OpenSession())
{
return session.Query<Report>().Where(r => Regex.IsMatch(r.Title, pSearchterm) || Regex.IsMatch(r.Text, pSearchterm))
.OrderBy(r => r.Open).OrderBy(r => r.LastEdited).Skip(pPageNum * pPageSize).Take(pPageSize);
}
}
答案 0 :(得分:0)
您应该明确打开连接。
尝试:
using (var client = new SearchServiceClient())
{
client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
client.Open();
ViewBag.Results = client.SearchReports(searchTerm, page, 50);
client.Close();
}