Inquiridor
Conectar a um Web Service via Windows Service

Pergunta
-
Olá galera!
Estou com um grande problema: tenho uma aplicação em Windows Form que faz comunicação com um Web Service e preciso fazer uma aplicação em Windows service que converse com esse Web Service, mas ao tentar estabelecer comunicação na aplicação Windows Service é disparado um erro de "EndPointNotFoundException". O código que eu estou utilizando é o mesmo que usei em Windows Form e que funciona.
Alguém aí sabe se existe algum detalhe a ser feito em Windows Service pra estabelecer essa comunicação ou conhece algum artigo que consiga me orientar a fazer uma aplicação com este recurso?
Todas as Respostas
-
Fillipe,
Este problema pode ser devido a restrições de segurança do serviço, tente usar a conta Network Service para a execução do seu serviço que acho que deve resolver o seu problema.
at.,
Rogério de Resende Ohashi | Ohashi.NET (.NET, Security, C#, WinForms, WCF, Workflow, Azure, Windows Phone, Mono) -
Olá Rogério
Tentei instalar o serviço com o Account setado para NetworkService mas o erro persiste ainda:
{System.ServiceModel.EndpointNotFoundException: Não foi possível a conexão com http://web.hindi.com.br/WebService/ApontamentoHindi.asmx. Código de erro TCP 10060: Uma tentativa de conexão falhou porque o componente conectado não respondeu
corretamente após um período de tempo ou a conexão estabelecida falhou
porque o host conectado não respondeu 174.37.39.180:80. ---> System.Net.WebException: Impossível conectar-se ao servidor remoto ---> System.Net.Sockets.SocketException: Uma tentativa de conexão falhou porque o componente conectado não respondeu
corretamente após um período de tempo ou a conexão estabelecida falhou
porque o host conectado não respondeu 174.37.39.180:80
em System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
em System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP)
em System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception)
--- Fim do rastreamento de pilha de exceções internas ---
em System.Net.HttpWebRequest.GetRequestStream(TransportContext& context)
em System.Net.HttpWebRequest.GetRequestStream()
em System.ServiceModel.Channels.HttpOutput.WebRequestHttpOutput.GetOutputStream()
--- Fim do rastreamento de pilha de exceções internas ---
Server stack trace:
em System.ServiceModel.Channels.HttpOutput.WebRequestHttpOutput.GetOutputStream()
em System.ServiceModel.Channels.HttpOutput.Send(TimeSpan timeout)
em System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.SendRequest(Message message, TimeSpan timeout)
em System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
em System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
em System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
em System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
em System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
em System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Exception rethrown at [0]:
em System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
em System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
em Hindi.ApontamentoWindowsService.HindiApontamentoWS.ApontamentoHindiSoap.ValidaRegistro(ValidaRegistroRequest request)
em Hindi.ApontamentoWindowsService.HindiApontamentoWS.ApontamentoHindiSoapClient.Hindi.ApontamentoWindowsService.HindiApontamentoWS.ApontamentoHindiSoap.ValidaRegistro(ValidaRegistroRequest request) na C:\Projetos\Hindi.root\Hindi.ApontamentoWindowsService\Service References\HindiApontamentoWS\Reference.cs:linha 701
em Hindi.ApontamentoWindowsService.HindiApontamentoWS.ApontamentoHindiSoapClient.ValidaRegistro(String registro) na C:\Projetos\Hindi.root\Hindi.ApontamentoWindowsService\Service References\HindiApontamentoWS\Reference.cs:linha 708
em Hindi.ApontamentoWindowsService.Monitor.serialPort_DataReceived(Object sender, SerialDataReceivedEventArgs e) na C:\Projetos\Hindi.root\Hindi.ApontamentoWindowsService\Monitor.cs:linha 166} -
Fillipe,
O problema que está parecendo é que a sua requisição está demorando demais e então dá Timeout, tente aumentar o tempo da requisição para tentar identificar porque isto está acontecendo, veja estas threads:
http://social.msdn.microsoft.com/Forums/en/wcf/thread/360f7997-82f8-40d0-8fd5-8cbbf1c44534
http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/84551e45-19a2-4d0d-bcc0-516a4041943d/
at.,
Rogério de Resende Ohashi | Ohashi.NET (.NET, Security, C#, WinForms, WCF, Workflow, Azure, Windows Phone, Mono)