Calling webserivce giving Error in Windows service but WebApplication& Windows Application Successfu

N

nRk

Hi,
I am creating a windows service..
in that i am connecitng to a webservice and retrieving the data by
calling a web method. This calling will be done every 5 min once and
the data will be stored in the database.

I added a web reference.. successfully.
proxy class generated..
installed as windows service
I am getting error when It connecting webservice and calling web
method.

But when I work with same in Normal windows application.. I am
successfully connecting to the webservice and able to call web method.

Working in Web application also successfully.

GIVING PROBLEM ONLY IN WINDOWS SERVICE .

The following is the class having Single method. "CallWebservice()"
which I am calling
==================================================================
public class TestClass
{
ILogManager log = LogManager.Instance;

public void CallWebservice()
{
log.Log(LogTypeEnum.INFO, "Starting windows service
calling..............!");
MgmtServicesSoap mgmtServiceProxy = new MgmtServicesSoap
();
try
{
log.Log(LogTypeEnum.INFO, "Connecting to webserice for
tesing..");
mgmtServiceProxy.PreAuthenticate = true;
mgmtServiceProxy.AllowAutoRedirect = true;
mgmtServiceProxy.Proxy = WebRequest.DefaultWebProxy;

NetworkCredential networkCredential = new
NetworkCredential("xxxxx", "xxxxxx");
CredentialCache credentialCache = new CredentialCache
();
credentialCache.Add(new Uri(mgmtServiceProxy.Url),
"Basic", networkCredential);
mgmtServiceProxy.Credentials = credentialCache;

log.Log(LogTypeEnum.INFO, "Proxy class initialized.");
string responseXmlString =
mgmtServiceProxy.getTransactionStatus("143566");
log.Log(LogTypeEnum.INFO, "Proxy class initialized
succesfully and connected to webservice.");
log.Log(LogTypeEnum.INFO, responseXmlString);

}
catch (Exception ex)
{
log.Log(LogTypeEnum.ERROR, "Error occured while
connecting to the webservice.");
log.Log(ex);
}
}

}

=====================
Windows service startup code
======================
protected override void OnStart(string[] args)
{
log.Log(LogTypeEnum.INFO, "Starting windows
service..............!");
MgmtServicesSoap mgmtServiceProxy = new MgmtServicesSoap
();
try
{
TestClass ss = new TestClass();
ss.CallWebservice();
}
catch (Exception ex)
{
log.Log(LogTypeEnum.ERROR, "Error occured while
connecting to the webservice.");
log.Log(ex);
}
}

==================================
Error
==================================
ExceptonType WebException : Unable to connect to the remote server
StackTrace :
at System.Net.HttpWebRequest.GetRequestStream()
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke
(String methodName, Object[] parameters)
at
TestindABSService.gov.energystar.estar8.MgmtServicesSoap.getTransactionStatus
(String TXNS_ID) in D:\Share\Testingservice\Web References
\gov.energystar.estar8\Reference.cs:line 379
at TestindABSService.TestClass.CallWebservice() in D:\Share
\Testingservice\TestindABSService\TestClass.cs:line 31
2008-12-08T18:38:34.6601 :: Error: ExceptonType SocketException : A
connection attempt failed because the connected party did not properly
respond after a period of time, or established connection failed
because connected host has failed to respond xxx.xxx.xx.xxx:443
StackTrace :
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, Exception& exception)
 
J

Jeff Johnson

But when I work with same in Normal windows application.. I am
successfully connecting to the webservice and able to call web method.

Working in Web application also successfully.

GIVING PROBLEM ONLY IN WINDOWS SERVICE .

Is it possible that the account the service is running under simply doesn't
have network access?
 
N

nRk

Is it possible that the account the service is running under simply doesn't
have network access?

Hi
Thanks for the fast reply..

I started windows service with differenct account..
Like LocalSystem , UserAccount.. Networkservice account..
Actually the current user account is type of Administrator for the
system.

thanks
nrk
 
O

Ollis

nRk said:
Hi,
I am creating a windows service..
in that i am connecitng to a webservice and retrieving the data by
calling a web method. This calling will be done every 5 min once and
the data will be stored in the database.

I added a web reference.. successfully.
proxy class generated..
installed as windows service
I am getting error when It connecting webservice and calling web
method.

But when I work with same in Normal windows application.. I am
successfully connecting to the webservice and able to call web method.

Working in Web application also successfully.

GIVING PROBLEM ONLY IN WINDOWS SERVICE .

ExceptonType SocketException : A
connection attempt failed because the connected party did not properly
respond after a period of time, or established connection failed
because connected host has failed to respond xxx.xxx.xx.xxx:443

------------------------------------------------------------------------------------------

The above kind of seems that you may be having a firewall issuse (blocked
port) as something is happening with TCP port 443, the HTTPS port.

Is all this you're talking about happening on the localhost/machine or a
remote IP/machine?
 
N

nRk

Hi
Thanks for the reply..

As you said there might be firewall issue.. Or port 443 issue..
It working fine in the Windows application without any problem. I am
receiving response what I expected (correct one).

In windows forms I added reference of the window service project and
called class.. as like an button click I did like this.

try
{
TestClass ss = new TestClass();
ss.CallWebservice();
}
catch (Exception ex)
{
log.Log(LogTypeEnum.ERROR, "Error occured while
connecting to the webservice.");
log.Log(ex);
}

It works fine without any problem... When it is working fine the same
why it is not working in the windows service....

Help to get out of this issue...

thanks
nrk
 
M

Mr. Arnold

Hi
Thanks for the reply..

As you said there might be firewall issue.. Or port 443 issue..
It working fine in the Windows application without any problem. I am
receiving response what I expected (correct one).


What happens when you try to consume the Web service in a Console
Application that is the Web client? And how is port 443 involved? Do you
know that you are using HTTPS for the Web service? Is this Web service being
consumed on localhost/IIS running this Web service or is the Web service
being consumed over HTTP a Internet or Intranet solution on a remote Web
server?
 
N

nRk

Hi Arnold

Thanks
As you said.. Console I didn't try..
The webservice I am consuming is developed using JAVA.
This webservice hosted some other remote machine, not in local machine
IIS.
It is consumed over internet.. not Intranet
I will try with console application ... .

thanks
nrk
 
O

Ollis

nRk said:
Hi Arnold

Thanks
As you said.. Console I didn't try..
The webservice I am consuming is developed using JAVA.
This webservice hosted some other remote machine, not in local machine
IIS.
It is consumed over internet.. not Intranet
I will try with console application ... .

Well, I can see the HTTPS TCP port 443 coming into play here possibly on
a remote Web server and a Web service that's using HTTPS, because the
error message you have provided is talking about TCP 443 the HTTPS port.

I don't know what trying to do here, as I am not privileged to the
information that you have. But if this is a 3rd party vendor Web
service, then you need to be in contact with the 3rd party vendor about
the consumption of the Web service from your Web service client solution
via a Windows desktop, ASP.Net, Windows service or Console application.
 
N

nRk

Hi Ollis

As you said I am tring to connect third party webservice developed in
Java..

One thing I am still in doubt.. why it is not working only in
WindowService, it is working in asp.net web application & C# Windows
application.

The exception/Error comming only When I am trying to connect in
Windows Service...?

Can you help me on this issue?

thanks
nrk
 
N

nRk

Hi
Thanks for all for your support
I am able to find out the solution

I changed the proxy settings like this..
from
mgmtServiceProxy.Proxy = WebRequest.DefaultWebProxy; (giving
error, But is the wrong )
to
mgmtServiceProxy.Proxy = new WebProxy("10.108.26.212", 80);

Or can be used

<system.net>
<defaultProxy>
<proxy
proxyaddress = "http://10.108.26.212:80"/>
</defaultProxy>
</system.net>


thanks
nrk
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top