【问题标题】:Messages via SOAP throws CommunicationException通过 SOAP 的消息抛出 CommunicationException
【发布时间】:2010-12-25 19:59:47
【问题描述】:

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

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

这就是我的 web 服务客户端的设置方式:

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)

【问题讨论】:

    标签: c# .net wcf distributed


    【解决方案1】:

    从异常看来,您的服务在处理过程中正在关闭底层连接。您能否验证您的服务在客户端中发生请求时仍在运行。

    在最坏的情况下添加一些 Console.WriteLine 消息记录服务的启动和停止。

    【讨论】:

    • 两个第一次调用服务就可以了。之后的其余部分不是。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-29
    • 2015-07-29
    • 1970-01-01
    • 1970-01-01
    • 2011-10-26
    相关资源
    最近更新 更多