473,670 Members | 2,563 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

windows service (c#) through proxy

6 New Member
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 11006
Plater
7,872 Recognized Expert Expert
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
calinux
6 New Member
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 Recognized Expert Expert
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
calinux
6 New Member
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 Recognized Expert Expert
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_MACH INE instead of HKEY_CURRENT_US ER
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
calinux
6 New Member
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_nam e>service hung on starting.

any idea?
thank u in advance!

calin
Oct 29 '08 #7
Plater
7,872 Recognized Expert Expert
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
calinux
6 New Member
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 Recognized Expert Specialist
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
2145
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 our Internet proxy server (I was trying to contact an internal machine). Upon digging into the code a little, I found that urllib2 was pulling the proxy information out of the Windows registry (Internet Explorer uses these settings). However,...
5
980
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 without a hitch). Before I use this class, I make the necessary calls to instantiate a WebProxy class and then pass in my credentials to set the WebProxy.Credentials property so I can get through the proxy server.
3
3802
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 who are behind SOCKS proxies. My app also has corporate clients that are behind a HTTP proxy. Is there a way for the windows app to consume a web service through a HTTP proxy? Please post any relevant code you have, THANKS!
2
2046
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 you are developing on a machine that is behind a firewall and a proxy server has not been explicitly specified for Internet Explorer connections. You need to explicitly specify the address and port of the proxy server on your network in order to make...
1
10138
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. Thanks in advance! Here is what I'm doing: In the windows app, I've set the current security principal as windowsprincipal
4
3991
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 told remoting was the way to go. So I got a client and a server program up and going and from the client I can call a routine in the server program. I can't figure out how to actually send data to the client. At the moment the client calls a...
3
13790
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 service run in an application pool which runs under a domain user, this domain user has permissions of accessing database and the connection to database is trusted connection. All these work well. The web application will be used in internet (not...
0
1922
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 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...
0
5709
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 service as a console application, there are no problems. I can run svcutil.exe against that address and it generates the proxy. However, when I compile that service in release mode, and install it on the workstation using InstallUtil, I get an error...
0
8466
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
8384
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
8901
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...
1
8591
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8659
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
4208
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
4388
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2799
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
2037
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.