我正在测试一个有两个表(Satellite和Channel)的数据库,因为我需要使用WCF来公开它。幸运的是,我现在尝试了我所知道的和在线的所有内容,而且我无法解决问题。
这是服务合约IService.cs
[ServiceContract]
public interface IService
{
[OperationContract]
List<Satalite> SelectSatalite(int satNum);
[OperationContract]
List<Satalite> SataliteList();
[OperationContract]
List<Channel> ChannelList(int satNum);
[OperationContract]
String Sat(int satNum);
}
这是Service.svc.cs
文件
public class Service : IService
{
DataDbDataContext DbObj = new DataDbDataContext();
public List<Satalite> SataliteList()
{
var satList = from r in DbObj.Satalites
select r;
return satList.ToList();
}
public List<Satalite> SelectSatalite(int satNum)
{
var satList = from r in DbObj.Satalites
where r.SateliteID == satNum
select r;
return satList.ToList();
}
public List<Channel> ChannelList(int satNum)
{
var channels = from r in DbObj.Channels
where r.SateliteID == satNum
select r;
return channels.ToList();
}
public String Sat(int satNum)
{
Satalite satObj = new Satalite();
satObj = DbObj.Satalites.Single(p => p.SateliteID == satNum);
return satObj.Name;
}
}
每当我尝试运行前三个时,我在使用wcftestclient.exe
进行测试时出错,最后一个没有问题。
基础连接已关闭:连接已关闭 出乎意料。
服务器堆栈跟踪:
at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException) webException,HttpWebRequest请求,HttpAbortReason abortReason)
at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan) 超时)
在System.ServiceModel.Channels.RequestChannel.Request(消息消息, TimeSpan超时)
在System.ServiceModel.Dispatcher.RequestChannelBinder.Request(消息 消息,TimeSpan超时)
在System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway,ProxyOperationRuntime操作,Object [] ins, 对象[]出局,TimeSpan超时)
在System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage) methodCall,ProxyOperationRuntime operation)
在System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage 消息)在[0]处重新抛出异常:
在System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg,IMessage retMsg)
在System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&amp; msgData,Int32类型)在IService.SelectSatalite(Int32 satNum)
在ServiceClient.SelectSatalite(Int32 satNum)内部异常:底层连接已关闭:连接 意外关闭。
在System.Net.HttpWebRequest.GetResponse()
at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan) 超时)
我理解的是,对于作为数据库表的自定义类,如果我使用.net编译器的已知类型(例如int
或string
),则会发生错误。没有问题。幸运的是,我没有找到解决方案。
答案 0 :(得分:1)
错误似乎是以下两个原因之一:
超时,因为您返回了太多数据,例如从数据库中选择数据需要太长时间才能使服务方法及时完成
或强>
邮件大小太大,因为您选择了太多数据,因此在返回整个数据之前WCF通信中止
我的解决方案:
尝试此操作 - 如果您将方法更改为:
public List<Satalite> SataliteList(int count)
{
var satList = (from r in DbObj.Satalites
select r).Take(count);
return satList.ToList();
}
您可以使用例如WCF测试客户端调用此方法吗? count = 10
或count = 50
??
答案 1 :(得分:0)
调整服务器和客户端的超时设置将对您有所帮助。
服务器端调整绑定元素的 SendTimeout 属性,并在客户端调整绑定元素的 RecieveTimeout 属性。
谢谢,