473,695 Members | 1,560 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Cre ate(webServiceU rl);
obj.Method = "POST";
obj.ContentType = "applicatio n/x-www-form-urlencoded";
obj.Headers.Add ("Authenticatio n", Password);
StreamWriter sw= new StreamWriter(ob j.GetRequestStr eam());
sw.Write(Query) ;

The exception returned:
"System.Net.Web Exception: Unable to connect to the remote server --->
System.Net.Sock ets.SocketExcep tion: No connection could be made because the
target machine actively refused it at
System.Net.Sock ets.Socket.DoCo nnect(EndPoint endPointSnapsho t, SocketAddress
socketAddress) at System.Net.Sock ets.Socket.Inte rnalConnect(End Point
remoteEP) at System.Net.Serv icePoint.Connec tSocketInternal (Boolean
connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address,
ConnectSocketSt ate 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 10862
"GD" <jb*****@yahoo. comwrote in message
news:uw******** ******@TK2MSFTN GP05.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.Cre ate(webServiceU rl);
obj.Method = "POST";
obj.ContentType = "applicatio n/x-www-form-urlencoded";
obj.Headers.Add ("Authenticatio n", Password);
StreamWriter sw= new StreamWriter(ob j.GetRequestStr eam());
sw.Write(Query) ;

The exception returned:
"System.Net.Web Exception: Unable to connect to the remote server --->
System.Net.Sock ets.SocketExcep tion: No connection could be made because
the
target machine actively refused it at
System.Net.Sock ets.Socket.DoCo nnect(EndPoint endPointSnapsho t,
SocketAddress
socketAddress) at System.Net.Sock ets.Socket.Inte rnalConnect(End Point
remoteEP) at System.Net.Serv icePoint.Connec tSocketInternal (Boolean
connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address,
ConnectSocketSt ate 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.saunder s at trizetto.comwro te in message
news:ud******** ********@TK2MSF TNGP04.phx.gbl. ..
"GD" <jb*****@yahoo. comwrote in message
news:uw******** ******@TK2MSFTN GP05.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:

HttpWebReque st obj = (HttpWebRequest )WebRequest.Cre ate(webServiceU rl);
obj.Method = "POST";
obj.ContentTyp e = "applicatio n/x-www-form-urlencoded";
obj.Headers.Ad d("Authenticati on", Password);
StreamWriter sw= new StreamWriter(ob j.GetRequestStr eam());
sw.Write(Query );

The exception returned:
"System.Net.We bException: Unable to connect to the remote server --->
System.Net.Soc kets.SocketExce ption: No connection could be made because
the
target machine actively refused it at
System.Net.Soc kets.Socket.DoC onnect(EndPoint endPointSnapsho t,
SocketAddres s
socketAddres s) at System.Net.Sock ets.Socket.Inte rnalConnect(End Point
remoteEP) at System.Net.Serv icePoint.Connec tSocketInternal (Boolean
connectFailure , Socket s4, Socket s6, Socket& socket, IPAddress& address,
ConnectSocketS tate 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******** ********@TK2MSF TNGP03.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.saunder s at trizetto.comwro te in message
news:eM******** ******@TK2MSFTN GP04.phx.gbl...
"GD" <jb*****@yahoo. comwrote in message
news:%2******** ********@TK2MSF TNGP03.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.Http WebRequest httpRequest =
(System.Net.Htt pWebRequest)Sys tem.Net.WebRequ est.Create("htt p://medpune_ws15/TestService/Service1.asmx?o p=HelloWorld");
httpRequest.Kee pAlive = false;
httpRequest.Pro tocolVersion = HttpVersion.Ver sion10;
System.IO.Strea m httpRequestStre am = null;
byte[] requestBuffer = System.Text.Enc oding.UTF8.GetB ytes("test");
httpRequest.Met hod = "POST";
httpRequest.Con tentType = "applicatio n/x-www-form-urlencoded";
httpRequest.Con tentLength = requestBuffer.L ength;
httpRequest.Tim eout = 10000;
httpRequestStre am = httpRequest.Get RequestStream() ;
httpRequestStre am.Write(reques tBuffer,0,reque stBuffer.Length );
httpRequestStre am.Close();
System.Net.Http WebResponse httpResponse = null;
httpResponse = (System.Net.Htt pWebResponse)ht tpRequest.GetRe sponse();
Any help is appreciated.

Thanks in advance,
Mani Kumar

"John Saunders [MVP]" wrote:
"GD" <jb*****@yahoo. comwrote in message
news:uw******** ******@TK2MSFTN GP05.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.Cre ate(webServiceU rl);
obj.Method = "POST";
obj.ContentType = "applicatio n/x-www-form-urlencoded";
obj.Headers.Add ("Authenticatio n", Password);
StreamWriter sw= new StreamWriter(ob j.GetRequestStr eam());
sw.Write(Query) ;

The exception returned:
"System.Net.Web Exception: Unable to connect to the remote server --->
System.Net.Sock ets.SocketExcep tion: No connection could be made because
the
target machine actively refused it at
System.Net.Sock ets.Socket.DoCo nnect(EndPoint endPointSnapsho t,
SocketAddress
socketAddress) at System.Net.Sock ets.Socket.Inte rnalConnect(End Point
remoteEP) at System.Net.Serv icePoint.Connec tSocketInternal (Boolean
connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address,
ConnectSocketSt ate 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**@discussio ns.microsoft.co mwrote in message
news:C9******** *************** ***********@mic rosoft.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.Http WebRequest httpRequest =
(System.Net.Htt pWebRequest)Sys tem.Net.WebRequ est.Create("htt p://medpune_ws15/TestService/Service1.asmx?o p=HelloWorld");
httpRequest.Kee pAlive = false;
httpRequest.Pro tocolVersion = HttpVersion.Ver sion10;
System.IO.Strea m httpRequestStre am = null;
byte[] requestBuffer = System.Text.Enc oding.UTF8.GetB ytes("test");
httpRequest.Met hod = "POST";
httpRequest.Con tentType = "applicatio n/x-www-form-urlencoded";
httpRequest.Con tentLength = requestBuffer.L ength;
httpRequest.Tim eout = 10000;
httpRequestStre am = httpRequest.Get RequestStream() ;
httpRequestStre am.Write(reques tBuffer,0,reque stBuffer.Length );
httpRequestStre am.Close();
System.Net.Http WebResponse httpResponse = null;
httpResponse = (System.Net.Htt pWebResponse)ht tpRequest.GetRe sponse();
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 GetRequestStrea m and GetResponseStre am
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.Cre ate(webServiceU rl);
obj.Method = "POST";
obj.ContentType = "applicatio n/x-www-form-urlencoded";
obj.Headers.Add ("Authenticatio n", Password);
StreamWriter sw= new StreamWriter(ob j.GetRequestStr eam());
sw.Write(Query) ;

The exception returned:
"System.Net.Web Exception: Unable to connect to the remote server --->
System.Net.Sock ets.SocketExcep tion: No connection could be made because the
target machine actively refused it at
System.Net.Sock ets.Socket.DoCo nnect(EndPoint endPointSnapsho t, SocketAddress
socketAddress) at System.Net.Sock ets.Socket.Inte rnalConnect(End Point
remoteEP) at System.Net.Serv icePoint.Connec tSocketInternal (Boolean
connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address,
ConnectSocketSt ate 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
2398
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 will be returned as DataSet. Now, here's the problem. On .NET Framework 1.1, if any rows in the dataset returned contain errors (marked by calling the SetColumnError() method or
4
6207
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 pass the data to the web service. I already modified both web.config files and changed maxRequestLength to 60000(kb). When I debug the upload process, it seems the Web application can get the 50M file and read the data without problem, but when the...
7
3087
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 works fine. So I deploy the webservice on a remote machine (Linux box) and I get an error when calling the service. BUT: I can retrieve the WSDL and make a webreference in my VS.NET project, so obviously I (or more correct: My VS.NET project) am...
0
1049
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 get a response from java server on the form, i'm getting the following error: There is an error in XML document (1, 358) Does this have something to do with a java serialised object not being able to get deserialised in dot net? Or is it...
10
19148
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 than 90 seconds. I am running VS.Net and the app is ASP.Net, written using VB.Net. The app calls an asp.Net web service to retrieve the report. Both the web site and the web service are running locally on my PC. I have tried modifying the...
1
4106
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 has timed out. If I continue by pressing F10, the process starts again and everything is fine. After some time again it will stop, show me an error on the line where I am calling webservice and if i say F10, it will again continue. I wanted to...
3
2341
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 language="JavaScript"> var iCallID;
3
7754
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 services (secure meaning windows authentication credentials must be used to access the web services). The problem is that when the web apps attempt to access a web service they are receiving 401: unathorized. - The apps are all running on web...
0
1686
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 Access turned off for the folder that contains the webservice .ASMX file. When I hit a certain page on Machine A, it will call the web service on Machine A, and then it will call the same web service on Machine B. Likewise, when I hit the same...
0
8623
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
8565
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9113
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8822
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4339
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4577
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2997
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2269
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1971
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.