Re: Error when calling a webservice from a windows service



Hi,
I am accessing webservice method using HttpWebRequest. The webmethod is
available if i call it using proxy, but sicne i want to add HTTP digest
security at server i am using HTTPWebRequest.
It returning with the error.
"The remote server returned an error: (500) Internal Server Error"

Below is the sample code.

System.Net.HttpWebRequest httpRequest =
(System.Net.HttpWebRequest)System.Net.WebRequest.Create("http://medpune_ws15/TestService/Service1.asmx?op=HelloWorld";);
httpRequest.KeepAlive = false;
httpRequest.ProtocolVersion = HttpVersion.Version10;
System.IO.Stream httpRequestStream = null;
byte[] requestBuffer = System.Text.Encoding.UTF8.GetBytes("test");
httpRequest.Method = "POST";
httpRequest.ContentType = "application/x-www-form-urlencoded";
httpRequest.ContentLength = requestBuffer.Length;
httpRequest.Timeout = 10000;
httpRequestStream = httpRequest.GetRequestStream();
httpRequestStream.Write(requestBuffer,0,requestBuffer.Length);
httpRequestStream.Close();
System.Net.HttpWebResponse httpResponse = null;
httpResponse = (System.Net.HttpWebResponse)httpRequest.GetResponse();


Any help is appreciated.

Thanks in advance,
Mani Kumar

"John Saunders [MVP]" wrote:

"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: Basic question about sockets and security
    ... I'm just starting out in sockets/network programming, and I have a very basic question...what are the 'security' implications of opening up a socket? ... The server opens a socket, listens on a port, and accepts incoming connections. ... If the server receives a message from a client, it sends that message out to every client. ...
    (comp.lang.python)
  • Re: Error when calling a webservice from a windows service
    ... I am accessing webservice method using HttpWebRequest. ... "The remote server returned an error: ... System.IO.Stream httpRequestStream = null; ... Ok, so, again, what leads you to believe this is a security problem? ...
    (microsoft.public.dotnet.framework.webservices)
  • Basic question about sockets and security
    ... The server opens a socket, listens on a port, and accepts incoming ... server receives a message from a client, it sends that message out to every ... I have no real security ...
    (comp.lang.python)
  • Re: How to terminate a socket in CLOSE_WAIT state
    ... FTP Server fixed for certain FTP clients who use both passive ... This was causing a PASSIVE opened socket to be left ... but instead expect the "half close" from the receiver. ... this sends a TCP/IP FIN packet to the ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Socket switch delay
    ... both at the client and at the server (and why ... would you set the send buffer size to zero on a non-overlapped ... One glaring error is your client does ... So when you use a single socket, ...
    (microsoft.public.win32.programmer.networks)