Re: Error when calling a webservice from a windows service

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



"GD" <jb48888@xxxxxxxxx> wrote in message
news:uw4OhpTgHHA.5052@xxxxxxxxxxxxxxxxxxxxxxx
Hi,

I am trying to call a webservice from a windows service application. It
works only if I launch the windows service app from VS.Net 2005 (Worked
around from Main()) or from a winform test application. However, it
generates a kind of security error after I install and start the service
in
my Window Server machine. I believe that it is related to authentication.
The following is the sample code:

HttpWebRequest obj = (HttpWebRequest)WebRequest.Create(webServiceUrl);
obj.Method = "POST";
obj.ContentType = "application/x-www-form-urlencoded";
obj.Headers.Add("Authentication", Password);
StreamWriter sw= new StreamWriter(obj.GetRequestStream());
sw.Write(Query);

The exception returned:
"System.Net.WebException: Unable to connect to the remote server --->
System.Net.Sockets.SocketException: No connection could be made because
the
target machine actively refused it at
System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot,
SocketAddress
socketAddress) at System.Net.Sockets.Socket.InternalConnect(EndPoint
remoteEP) at System.Net.ServicePoint.ConnectSocketInternal(Boolean
connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address,
ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, ...."


What leads you to believe that this is a security error? What if this
exception actually means what it says? That the remote server "actively
refused" the connection. The question then is why was it refused? Was some
other process already using the same socket and wasn't listening? Or worse,
perhaps the socket is simply not open?

At any rate, I think that's the direction you should look in, unless you're
actually seeing an exception that explicitly mentions security.
--

John Saunders [MVP]


.



Relevant Pages

  • Re: ASP.NET 2.0 - a newbie question
    ... the exception can be identified using the exception stack trace below. ... established connection failed because connected host has failed to ... connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& ... Microsoft SQL Server? ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: ASP.NET 2.0 - a newbie question
    ... I try to build the first app described in "ASP.NET 2.0 Everyday Apps ... the exception can be identified using the exception stack trace below. ... A connection attempt failed because the ... connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& ...
    (microsoft.public.dotnet.framework.aspnet)
  • ASP.NET 2.0 - a newbie question
    ... Is there some experienced ASP.NET 2.0 developer, ... the exception can be identified using the exception stack trace below. ... A connection attempt failed because the ... connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: An existing connection was forcibly closed by the remote host...
    ... EndReceivewill throw "Can't access disposed object" exception whenever the connection is terminated. ... In MS .NET Socket implementation there is no mechanism for the socket object to signal to the main thread that it is about to be disposed. ... public Socket ClientSocket ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Sending email via SMTP
    ... A connection attempt failed because the ... Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState ... state, IAsyncResult asyncResult, Int32 timeout, Exception& exception) ...
    (microsoft.public.dotnet.framework.windowsforms)