2009-12-11 3 views
0

Это как моя служба создана:сообщения через SOAP бросает CommunicationException

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

Это как мой клиент вебсервис настроен:

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

Но когда я использую его в моем приложении Я получаю System.ServiceModel.CommunicationException. Я давно пробовал, и знаю, как его решить. Googling это показывает что-то об установке 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) 

ответ

0

Из исключения это выглядит, как ваша служба закрывает основное соединение во время обработки. Можете ли вы проверить, что ваша служба все еще работает в точке, когда запрос выполняется в клиенте.

В худшем случае добавьте некоторые сообщения о запуске и остановке службы Console.WriteLine.

+0

Два первых вызова службы в порядке. Остальное после этого - нет. –