By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,247 Members | 1,223 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,247 IT Pros & Developers. It's quick & easy.

Error when calling a webservice from a windows service

P: n/a
GD
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(Bool ean
connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address,
ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, ...."

I did some research online. Many people got similar errors. However, I have
not found a solution yet.

Any solution or suggestion is appreciated.

GD

Apr 17 '07 #1
Share this Question
Share on Google+
7 Replies


P: n/a
"GD" <jb*****@yahoo.comwrote in message
news:uw**************@TK2MSFTNGP05.phx.gbl...
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(Bool ean
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]
Apr 18 '07 #2

P: n/a
GD
Thanks for reply.

The windows service works at my home. I believe that the port or socket that
the service uses is blocked at my company network.

Anyone can point out how to configure the port or socket in a Windows Server
or network please?

Thanks.

GD

"John Saunders [MVP]" <john.saunders at trizetto.comwrote in message
news:ud****************@TK2MSFTNGP04.phx.gbl...
"GD" <jb*****@yahoo.comwrote in message
news:uw**************@TK2MSFTNGP05.phx.gbl...
>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(Bool ean
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]


Apr 18 '07 #3

P: n/a
"GD" <jb*****@yahoo.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
Thanks for reply.

The windows service works at my home. I believe that the port or socket
that the service uses is blocked at my company network.

Anyone can point out how to configure the port or socket in a Windows
Server or network please?

It's not that simple. There could be any number of reasons for this, and
you're going to need to track it down. You should inform the people who run
that server. Point them to this discussion thread, if you like.
--

John Saunders [MVP]
Apr 18 '07 #4

P: n/a
GD
It was the credential problem. After I added login information to the
service (in the service console), the query in the service works.

Thanks.

GD

"John Saunders [MVP]" <john.saunders at trizetto.comwrote in message
news:eM**************@TK2MSFTNGP04.phx.gbl...
"GD" <jb*****@yahoo.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>Thanks for reply.

The windows service works at my home. I believe that the port or socket
that the service uses is blocked at my company network.

Anyone can point out how to configure the port or socket in a Windows
Server or network please?


It's not that simple. There could be any number of reasons for this, and
you're going to need to track it down. You should inform the people who
run that server. Point them to this discussion thread, if you like.
--

John Saunders [MVP]


Apr 18 '07 #5

P: n/a
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.C reate("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,requestBuf fer.Length);
httpRequestStream.Close();
System.Net.HttpWebResponse httpResponse = null;
httpResponse = (System.Net.HttpWebResponse)httpRequest.GetRespons e();
Any help is appreciated.

Thanks in advance,
Mani Kumar

"John Saunders [MVP]" wrote:
"GD" <jb*****@yahoo.comwrote in message
news:uw**************@TK2MSFTNGP05.phx.gbl...
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(Bool ean
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]
Apr 27 '07 #6

P: n/a
"Mani" <Ma**@discussions.microsoft.comwrote in message
news:C9**********************************@microsof t.com...
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.C reate("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,requestBuf fer.Length);
httpRequestStream.Close();
System.Net.HttpWebResponse httpResponse = null;
httpResponse = (System.Net.HttpWebResponse)httpRequest.GetRespons e();
Any help is appreciated.
Ok, so, again, what leads you to believe this is a security problem? Isn't
it more likely a problem with the way you're sending your data?

Among other things, please try content type "text/xml". I have a working
tool that uses that.

Also, BTW, the streams returned from GetRequestStream and GetResponseStream
both implement IDisposable, so they should both be wrapped within a "using"
expression.
--
John Saunders [MVP]
Apr 27 '07 #7

P: n/a
Hi,

em trying to call webservice from windows service, i hv written the code
in app.config file to provide the information like webservice address. When i
run this windows service i em getting information displayed in the
EventViewer[System] which says Service Control Manager

ple can some one help me out. i would like to call the dll using the
webservice from the windows service, be coz as the application and the
Windows service gone use same Dll it will be wise to hv only one dll and both
the windows Application and Windows service will point to the same Dll.

--SK

"GD" wrote:
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(Bool ean
connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address,
ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, ...."

I did some research online. Many people got similar errors. However, I have
not found a solution yet.

Any solution or suggestion is appreciated.

GD

May 10 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.