473,320 Members | 1,865 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,320 software developers and data experts.

windows service (c#) through proxy

hi

i am developing a windows application (VS 2008 - .net 3.5) which is requesting some data from a server (XML) and depends by results it is doing something

this application is using a UI for load/ save setings and a windows service which is requesting data at each 20 minutes.

i realized that the form (UI) has no problem to communicate with server (with or without proxy) but windows service is working only when is no proxy.

can somebody help me? can be an example in c# or vb.

i really appreciate it
calin
Oct 27 '08 #1
9 10877
Plater
7,872 Expert 4TB
What do you mean by "no proxy" and with a proxy?
If your browser is using a Proxy, it does not mean your service is using the proxy too.
Or do you mean like the network that the PC with the service is attached to, has a proxy server that applies to every PC on that network, without any settings on the PCs?

If a pxoy server is indeed being the middleman for your requests, the webserver is probably going "hey, this isn't the computer/service i requested the XML data from, it must be bad data/not mine" and either ignores it or throws an error
Oct 28 '08 #2
Hi Plater

all time the service is trying to access DIRECT (doesn't matter if in IE is seted up a proxy)

Expand|Select|Wrap|Line Numbers
  1.  Dim objRequest As HttpWebRequest
  2.  objRequest = WebRequest.Create(URL + PostData)
  3.  Dim retProxy As WebProxy
  4.  Dim retURI As Uri
  5.  retURI = New Uri(URL)
  6.  retProxy = New WebProxy(WebRequest.DefaultWebProxy.GetProxy(retURI))
  7.  objRequest.Credentials = CredentialCache.DefaultCredentials
  8.  objRequest.Timeout = 30000   ' 30 secs
  9.  If retURI <> retProxy.Address Then
  10.           objRequest.Proxy = retProxy
  11.   End If
This code is working when is accessed from a form (working means that form is looking at IE proxy settings).. but id doesnot work when is accessed from windows service (windows service try to access DIRECT).

Thank you
Oct 28 '08 #3
Plater
7,872 Expert 4TB
Oh ok, let me make sure I understand this.
When you run the program as a form, the program gets the PROXY settings (via that default proxy settings) and works fine.
But as a SERVICE, the program is failing to get the proxy credentials?

I would venture that the problem is this: PROXY settings are generally on a "per user" level. When you run the program as a form, it gets the current user's proxy settings, which are configured. When run as a SERVICE, it runs as some other user (possibly some SYSTEM account) that does not have the PROXY server settings configured.
Try running the SERVICE with a specific user credentials that you know has the PROXY settings configured, and see if that helps?
Oct 28 '08 #4
Hi Plater

is all true what u said. the service is running like LocalSystem, but i need to be ran by localsystem. U know in vista is more complicate. for this i implemented Elevated method.

This service need to have ADMIN privileges. Any ideea how can i use default proxy in my windows service started like LocalSystem?

Thank you in advance
Calin
Oct 28 '08 #5
Plater
7,872 Expert 4TB
Hmm, the default proxy is the one configured by internet explorer right?
All those settings are kept in the registry.
Maybe you could find a way to either:
A) copy the registry keys over into the HKEY_LOCAL_MACHINE instead of HKEY_CURRENT_USER
B) Read the registry entry of another user and get the settings?
C) Find a way to apply the proxy settings to "all users of the computer)

Can't say as I know how to do any of those, but it might help you find something about it?
Oct 28 '08 #6
Hi Plater

i tried this, but u know virtualization in Vista! registry ideea is not good.
at setup process (installation) i am writing default proxy setings in a file. when i am running the service, i am reading the proxy from that file. i thought that this will solve the problem, but appear a new one:
The <my_service_name>service hung on starting.

any idea?
thank u in advance!

calin
Oct 29 '08 #7
Plater
7,872 Expert 4TB
Can you have your service output to its own log file somewhere?
Perhaps its throwing some kind of error that is not caught by eventlog stuff?
Just make an entry into that file like "Entering function: (whatever)", "leaving function (whatever)", etc etc
Then you could find where it is stalling out?
Oct 29 '08 #8
yes i implemented

Expand|Select|Wrap|Line Numbers
  1. Public Class pcksrv
  2.     Protected Overrides Sub OnStart(ByVal args() As String)
  3.         ' Add code here to start your service. This method should set things
  4.         ' in motion so your service can do its work.
  5.         LogInfo("Stariting the service")
  6.         myClock.Enabled = True
  7.  
  8.     End Sub
  9.  
  10.     Protected Overrides Sub OnStop()
  11.         LogInfo("Stoping the service")
  12.         myClock.Enabled = False
  13.     End Sub
  14.  
  15.     Public Shared Sub LogInfo(ByVal sMessage As String)
  16.         ' Write info into the event viewer
  17.         Try
  18.             Dim oEventLog As EventLog = New EventLog("Application")
  19.             If Not Diagnostics.EventLog.SourceExists("NotificationService") Then
  20.                 Diagnostics.EventLog.CreateEventSource("NotificationService", "Application")
  21.             End If
  22.             Diagnostics.EventLog.WriteEntry("NotificationService", sMessage, _
  23.                 System.Diagnostics.EventLogEntryType.Information)
  24.         Catch e As Exception
  25.         End Try
  26.     End Sub
  27.  
  28.     Private Sub myClock_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles myClock.Tick
  29.         LogInfo("Tic Tac 1")
  30.         CheckMyServer()
  31.         LogInfo("Tic Tac 2")
  32.     End Sub
  33. End Class
  34.  
but no luck, the service crashed before!
Oct 29 '08 #9
Curtis Rutland
3,256 Expert 2GB
Please enclose your posted code in [code] tags (See How to Ask a Question).

This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

Please use [code] tags in future.

MODERATOR
Oct 29 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Carl Waldbieser | last post by:
**** Post for FREE via your newsreader at post.usenet.com **** When using urllib2.urlopen() on my Windows 2000 machine at work, I was puzzled that I kept getting back authentication errors from...
5
by: Bill Hauver | last post by:
I am attempting to use a web service from my work pc which is behind a firewall. I have used wsdl.exe to create the web service reference class and added it to my project. (this seems to work...
3
by: Thomas Miller | last post by:
Is there ANY way for a windows app to consume a web service by going through a SOCKS proxy? This is a MUST for me because the windows app I am building will be deployed to many corporate clients...
2
by: Jeffrey Tate via DotNetMonster.com | last post by:
The error is: The proxy settings on this computer are not configured correctly for Web discovery. MSDN states that this is caused by: This error appears in the Add Web Reference dialog box if...
1
by: webserviceUser189 | last post by:
Hi, I'm trying to authenticate the user based on the credentials that I get from the client app, but I'm getting empty string as user name. Can somebody tell me if I'm doing anything wrong here....
4
by: WinDev | last post by:
We are trying to build a system where we have a Windows Service do some manipulation of data, and then sending the data to a Windows App. I had posted a question of how we should do this and was...
3
by: =?Utf-8?B?RGFuZGFuIFpoYW5n?= | last post by:
Now I have a web application, a web service and a SQL Server database. The Web application will invoke the web service, the web service invokes the SQL Server stored procedure. I let the web...
0
by: calinux | last post by:
hi i am developing a windows application (VS 2008 - .net 3.5) which is requesting some data from a server (XML) and depends by results it is doing something this application is using a UI for...
0
by: khurramlone | last post by:
I am trying to generate a client proxy from a WCF service library. I am using VS2005, .NET 3.0 on a Windows XP Pro workstation. The WCF service is hosted in a windows service. When I run the windows...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.