473,382 Members | 1,750 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Error when calling a webservice from a windows service

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
7 10837
"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
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
"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
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
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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Programatix | last post by:
Hi, I'm working on a project which includes XML WebServices and Windows Form application. The Windows Form application will call the XML WebServices to retrieve data from database. The data...
4
by: jf li | last post by:
I have a Asp.net web application and a Asp.net Web service application. The Web application is using HtmlInputFile to get a 50M size of file selected by end user, read the data of this file and...
7
by: Jorgen Haukland, Norway | last post by:
Hi, I have created a Java webservice which runs in IBM WebSphere appserver. I take the WSDL-file and create a VS.NET WinForm application and calls the service running on my PC and everything...
0
by: Nick | last post by:
Hi all, We currently have a web service developed in Java, which we're calling from a dot net coded windows form. this web service is returning an object of type abc (say). Now, when we try and...
10
by: Jim Underwood | last post by:
I am having a problem with my web page timng out while retrieving a long runnign report (90-120 seconds. I have tried modifying several settings in various places and cannot get it to run for more...
1
by: Pooja | last post by:
Hi, I am calling a web service to get Latitude and Longitude by sending a zip code. This is happening inside a loop (2000 - 3000 times). After say 80 times, it gives me an error - The operation...
3
by: Zeez | last post by:
Hi all, I have a webpage that calls a webservice found on a remote computer. Below is the code of my webpage: ===================================== <html> <head> <script...
3
by: Brad | last post by:
I'm setting up my new pc with all my VS.net projects and I'm missing something.....something I've done many times before without problem. I have several asp.net apps accessing secure .net web...
0
by: JeremyPollack | last post by:
Here's the situation : I have the same ASP.NET 2.0 web application running on both Machine A and Machine B. On both machines, I have Integrated Windows Authentication turned on, and Anonymous...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.