通过SOAP的消息抛出CommunicationException

时间:2009-12-11 20:39:39

标签: c# .net wcf distributed

这就是我的服务设置方式:

myServiceHost = new ServiceHost(typeof(ChatCommunicationService), new Uri("http://localhost:8080"));
myServiceHost.AddServiceEndpoint(typeof(IChatService), new WSHttpBinding(), "Soap");
myServiceHost.Open();

这就是我的webservice客户端的设置方式:

ChannelFactory<IChatService> scf = new ChannelFactory<IChatService>(new WSHttpBinding(), "http://localhost:8080/Soap");
_chatService = scf.CreateChannel();

但是当我在我的应用程序中使用它时,我得到了System.ServiceModel.CommunicationException。我已经尝试了很长时间,我知道如何解决它。谷歌搜索它显示了将keepalive设置为false但我不知道在哪里设置它。

注意:它在开始时工作(我可以通过SOAP发送消息)但它总是在同一个地方抛出异常。直接与我的数据库交谈我没有例外。我必须使用SOAP。

如果有人可以提供帮助,我将不胜感激:)

错误讯息:

System.ServiceModel.CommunicationException: The underlying connection was closed: A connection that was expected to be kept alive was closed by the server. ---> System.Net.WebException: The underlying connection was closed: A connection that was expected to be kept alive was closed by the server. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
   at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   --- End of inner exception stack trace ---
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   at System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   at System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userReA first chance exception of type 'System.ServiceModel.CommunicationException' occurred in mscorlib.dll
trievedStream, Boolean probeRead)
   --- End of inner exception stack trace ---
   at System.Net.HttpWebRequest.GetResponse()
   at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
   --- End of inner exception stack trace ---

Server stack trace: 
   at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)
   at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
   at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Channels.ClientReliableChannelBinder`1.RequestClientReliableChannelBinder`1.OnRequest(TRequestChannel channel, Message message, TimeSpan timeout, MaskingMode maskingMode)
   at System.ServiceModel.Channels.ClientReliableChannelBinder`1.Request(Message message, TimeSpan timeout, MaskingMode maskingMode)
   at System.ServiceModel.Channels.ClientReliableChannelBinder`1.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Security.SecuritySessionClientSettings`1.SecurityRequestSessionChannel.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

1 个答案:

答案 0 :(得分:0)

从例外情况看,您的服务在处理期间正在关闭基础连接。您是否可以验证您的服务是否仍在客户端发出请求时运行。

最坏的情况是添加一些Console.WriteLine消息,记录服务的开始和停止。

相关问题