【发布时间】:2015-07-29 05:10:51
【问题描述】:
我有两个项目。一个具有 wcf 服务和数据库。其他用于调用这些函数。如果我调用一个向数据库添加内容的 webservice 函数,它工作正常。但是当我调用一个从数据库中检索某些东西的函数时。我得到通信异常。我在 WebService.svc.cs 中调用的函数是:
public List<Artist> GetAllArtists()
{
Database1Entities db = new Database1Entities();
return (db.Artists).ToList();
}
我这样称呼它
protected void Page_Load(object sender, EventArgs e)
{
ServiceReference2.WebServiceClient o = new ServiceReference2.WebServiceClient();
Artist [] artists = o.GetAllArtists(); //Exception arises here
string str = "";
foreach (Artist artist in artists){
str += artist.ArtistID + " ";
}
Response.Write(str);
gv.DataSource = artists;
gv.DataBind();
}
例外:
System.ServiceModel.CommunicationException 未被用户代码处理 HResult=-2146233087 消息=接收 HTTP 时发生错误 回复http://localhost:23060/WebService.svc。这可能是由于 到不使用 HTTP 协议的服务端点绑定。这 也可能是由于 HTTP 请求上下文被 服务器(可能是由于服务关闭)。查看服务器日志 更多细节。 Source=mscorlib StackTrace:服务器堆栈跟踪:在 System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest 请求, HttpAbortReason abortReason) 在 System.ServiceModel.Channels.HttpChannelFactory1.HttpRequestChannel.HttpChannelRequest.WaitForReply(时间跨度 暂停) 在 System.ServiceModel.Channels.RequestChannel.Request(消息消息, 时间跨度超时) 在 System.ServiceModel.Dispatcher.RequestChannelBinder.Request(消息
消息,时间跨度超时) 在 System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] 出局,TimeSpan 超时) 在 System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall、ProxyOperationRuntime 操作) 在 System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage
信息) 在 [0] 处重新抛出异常: 在 System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) 在 System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&
msgData,Int32 类型) 在 WebLab6AlbumManagementSystemClient.ServiceReference2.IWebService.GetAllArtists() 在 WebLab6AlbumManagementSystemClient.ServiceReference2.WebServiceClient.GetAllArtists() 在 c:\Users\Muhammad Rehan\Documents\Visual Studio
2013\Projects\WebLab6AlbumManagementSystemClient\Service
References\ServiceReference2\Reference.cs:第 567 行 在 WebLab6AlbumManagementSystemClient.ViewAllArtists.Page_Load(对象
发件人,EventArgs e) 在 c:\Users\Muhammad Rehan\Documents\Visual
工作室
2013\Projects\WebLab6AlbumManagementSystemClient\ViewAllArtists.aspx.cs:line 16 在 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(对象发送者, 事件参数 e) 在 System.Web.UI.Control.OnLoad(EventArgs e) 在 System.Web.UI.Control.LoadRecursive() 在 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)InnerException:System.Net.WebException H结果=-2146233079 Message=底层连接已关闭:接收时发生意外错误。 源=系统 堆栈跟踪: 在 System.Net.HttpWebRequest.GetResponse() 在 System.ServiceModel.Channels.HttpChannelFactory1.HttpRequestChannel.HttpChannelRequest.WaitForReply(时间跨度 超时)InnerException:System.IO.IOException HResult=-2146232800 消息=无法从传输连接读取数据:现有 连接被远程主机强行关闭。源=系统 StackTrace:在 System.Net.Sockets.NetworkStream.Read(Byte[] 缓冲区, System.Net.PooledStream.Read(Byte[] 处的 Int32 偏移量,Int32 大小) 缓冲区,Int32 偏移量,Int32 大小)在 System.Net.Connection.SyncRead(HttpWebRequest 请求,布尔值 userRetrievedStream, Boolean probeRead) InnerException: System.Net.Sockets.SocketException HResult=-2147467259 消息=一个 现有连接被远程主机强行关闭 源=系统错误代码=10054 NativeErrorCode=10054 堆栈跟踪:在 System.Net.Sockets.Socket.Receive(Byte[] 缓冲区,Int32 偏移量,Int32 大小,SocketFlags socketFlags)在 System.Net.Sockets.NetworkStream.Read(Byte[] 缓冲区,Int32 偏移量, Int32 大小)InnerException:
【问题讨论】:
-
Artist是DataContract吗? -
这是 OperationContract。我的意思是 GetAllArtists() 是 OperationContract。而 Artist 顶部没有任何内容,而 Artist 是使用数据库中的 ado.net 实体数据模型从数据库自动生成的。