My WCF service is throwing Error when running through a windows service

827 views Asked by At

I have created one WCF service, in which I am reading the msn whether feeds and new feeds through HttpWebRequest and HttpWebResponse using C# coding. When I execute the service in my local PC its working fine and getting the feeds properly, not only in my system in allmost all our network systems too. I am using the CredentialCache.DefaultNetworkCredentials assigning as the default network credentials to the HttpWebRequest proxy credentials and also giving HttpWebRequest.DefaultWebProxy for the proxy of HttpWebRequest. Everything is working fine in my pc. And when I install the service in our server pc to the Windows services and start the service, for every time its throwing an unexpected error as follows

System.Net.WebException: The remote server returned an error: (403) Forbidden.
   at System.Net.HttpWebRequest.GetResponse()

I am unable to fix this bug in my server application. By copying the uri that I am requesting in my service, to a browser its getting the feeds in the server pc. But why its throwing an exception when running through a windows service (services.msc) ?? Hope any one can help me to solve this problem.

EDIT:

Actually, before I tried by giving the proxy username and password for proxy credentials and also specified proxy address through config entries, at that time it was working fine. But our plan is to remove the burden of providing the proxy ip address, username, password for every time. So, we planned to give it through default network credentials that are saved in system to bypass the proxy with the above given steps.

1

There are 1 answers

2
Damir Arh On BEST ANSWER

Do you have a proxy server set up in your company that requires authentication?

Try running the service using you identity instead of the built-in ones (Network Service, Local System) and see if that helps.

EDIT:

I guess it could depend how the proxy is configured but to use the default proxy settings you might need the service to run under a domain account having those properties correctly set. As a good practice use a dedicated service account instead of your own, of course.

Also you might want to take a look how to configure proxy in the config file instead of hard coding it.