Home All Groups Group Topic Archive Search About

Error when calling a webservice from a windows service

Author
17 Apr 2007 9:42 PM
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(Boolean
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

Author
18 Apr 2007 12:26 AM
Bryan Phillips
You will get this error if the web server is not listening for requests.
  Try using IE to hit the web service manually when you get this error.

On the web server, check the IIS logs to see if any traffic was recorded
and if so, check the Win32 and Http status codes.

--
Bryan Phillips
MCSD, MCDBA, MCSE
Blog:  http://bphillips76.spaces.live.com
Web Site:  http://www.composablesystems.net



Show quoteHide quote
"GD" <jb48***@yahoo.com> wrote in message
news:OmYVKlTgHHA.4032@TK2MSFTNGP02.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(Boolean
> 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
Are all your drivers up to date? click for free checkup

Author
18 Apr 2007 3:13 AM
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.

How to configure the port or socket in a Windows Server or network?

Thanks.

GD

Show quoteHide quote
"Bryan Phillips" <bphillips@nospam.spamcop.net.spammenot> wrote in message
news:O9ZANBVgHHA.4552@TK2MSFTNGP04.phx.gbl...
> You will get this error if the web server is not listening for requests.
> Try using IE to hit the web service manually when you get this error.
>
> On the web server, check the IIS logs to see if any traffic was recorded
> and if so, check the Win32 and Http status codes.
>
> --
> Bryan Phillips
> MCSD, MCDBA, MCSE
> Blog:  http://bphillips76.spaces.live.com
> Web Site:  http://www.composablesystems.net
>
>
>
> "GD" <jb48***@yahoo.com> wrote in message
> news:OmYVKlTgHHA.4032@TK2MSFTNGP02.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(Boolean
>> 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
>
Author
18 Apr 2007 9:37 PM
Bryan Phillips
The port that the web service will listen on is the same port configured
at the web site level in IIS Manager.  If there are any software or
hardware firewalls between your windows service and the web server, they
will need to be configured to allow traffic on that port.

--
Bryan Phillips
MCSD, MCDBA, MCSE
Blog:  http://bphillips76.spaces.live.com
Web Site:  http://www.composablesystems.net



Show quoteHide quote
"GD" <jb48***@yahoo.com> wrote in message
news:O6vEsdWgHHA.4916@TK2MSFTNGP06.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.
>
> How to configure the port or socket in a Windows Server or network?
>
> Thanks.
>
> GD
>
> "Bryan Phillips" <bphillips@nospam.spamcop.net.spammenot> wrote in message
> news:O9ZANBVgHHA.4552@TK2MSFTNGP04.phx.gbl...
> > You will get this error if the web server is not listening for requests.
> > Try using IE to hit the web service manually when you get this error.
> >
> > On the web server, check the IIS logs to see if any traffic was recorded
> > and if so, check the Win32 and Http status codes.
> >
> > --
> > Bryan Phillips
> > MCSD, MCDBA, MCSE
> > Blog:  http://bphillips76.spaces.live.com
> > Web Site:  http://www.composablesystems.net
> >
> >
> >
> > "GD" <jb48***@yahoo.com> wrote in message
> > news:OmYVKlTgHHA.4032@TK2MSFTNGP02.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(Boolean
> >> 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
> >
Author
18 Apr 2007 10:58 PM
GD
It turned out to be a credential problem. After I added login information to
the
service (in the service console), the query in the service works.

Thanks.

GD

Show quoteHide quote
"Bryan Phillips" <bphillips@nospam.spamcop.net.spammenot> wrote in message
news:ODwCKIggHHA.4516@TK2MSFTNGP03.phx.gbl...
> The port that the web service will listen on is the same port configured
> at the web site level in IIS Manager.  If there are any software or
> hardware firewalls between your windows service and the web server, they
> will need to be configured to allow traffic on that port.
>
> --
> Bryan Phillips
> MCSD, MCDBA, MCSE
> Blog:  http://bphillips76.spaces.live.com
> Web Site:  http://www.composablesystems.net
>
>
>
> "GD" <jb48***@yahoo.com> wrote in message
> news:O6vEsdWgHHA.4916@TK2MSFTNGP06.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.
>>
>> How to configure the port or socket in a Windows Server or network?
>>
>> Thanks.
>>
>> GD
>>
>> "Bryan Phillips" <bphillips@nospam.spamcop.net.spammenot> wrote in
>> message
>> news:O9ZANBVgHHA.4552@TK2MSFTNGP04.phx.gbl...
>> > You will get this error if the web server is not listening for
>> > requests.
>> > Try using IE to hit the web service manually when you get this error.
>> >
>> > On the web server, check the IIS logs to see if any traffic was
>> > recorded
>> > and if so, check the Win32 and Http status codes.
>> >
>> > --
>> > Bryan Phillips
>> > MCSD, MCDBA, MCSE
>> > Blog:  http://bphillips76.spaces.live.com
>> > Web Site:  http://www.composablesystems.net
>> >
>> >
>> >
>> > "GD" <jb48***@yahoo.com> wrote in message
>> > news:OmYVKlTgHHA.4032@TK2MSFTNGP02.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(Boolean
>> >> 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
>> >
>

Bookmark and Share