Referencing this answer, I'm attempting to establish a proxy connection for a service reference, but am having trouble verifying that it's actually being used.
In my app.config, I have
<system.net>
<defaultProxy useDefaultCredentials="true">
<proxy
usesystemdefault="False"
proxyaddress="http://proxyaddresst.com:80"
bypassonlocal="False"/>
</defaultProxy>
</system.net>
but would like to be able to list the address of the proxy being used in the program itself, through
Console.WriteLine(DateTime.Now.ToString("hh:mm:ss.fff") + " Proxy: " + ???);
Is there a way to do this? It seems simple, but so did setting up the proxy in the first place, and the program isn't working as expected. I'd like to either verify the proxy is in use (and discount it as necessary) or verify that it isn't (and then look for another way to integrate it).
Related
I need to configure a default proxy to enable Application Insights.
In an ASP.NET Web Api the default proxy can be set in the web.config like below:
<system.net>
<defaultProxy enabled="true" useDefaultCredentials="true">
<proxy proxyaddress="someaddress" bypassonlocal="True" />
</defaultProxy>
</system.net>
With this setting AI works fine. Unfortunately I could not find an option to set the proxy in appsettings.json. Is there any possibility to define the default proxy in an ASP.NET Core Web API?
Or do I have to configure the proxy in IIS, when the application is getting hosted with it?
Edit:
I am setting the default proxy now like this:
WebRequest.DefaultWebProxy = new WebProxy(new Uri("someaddress"), true)
{
UseDefaultCredentials = true
};
When getting the proxy with
WebRequest.DefaultWebProxy.GetProxy(new Uri("https://dc.services.visualstudio.com/v2/track"))
it returns the correct proxy.
Strange things happens when Fiddler is running.
As soon as Fiddler is running the application is logging successfully to AI. When closing Fiddler the logging breaks again.
Has anyone an idea?
Do you mean you want to configure HttpClient proxy globally?
If so, I am afraid it is impossible. You may consider creating an encapsulate class with accepting Proxy configuration and return a HttpClient, you could load the configuration from appsettings.json or anywhere
Perhaps your traffic is going through Fiddler Proxy so when Fiddler shuts down so as your connection to other services.
Just a small summary of the infrastructure. I have a webservice running on a server in India only accessible through the companies internal network. I'm located in Europe.
The webservice is hosted in its own windows service, so no IIS.
When starting the client the first call allways takes approx 22 sec., this is a simple "ping" operation, just asking if the server is there, so no logic on the server that takes any time.
I have tried this solution First call to a .net webservice is slow with a bypass list. But that doesn't seem to work, unless it's me doing something wrong ?
<bypasslist>
<add address="[a-z]+\.company_name\.com"/>
</bypasslist>
Where the server address is staging.company_name.com
I also tried the other solution that has been suggested in the post, but still no luck.
<configuration >
<system.net>
<defaultProxy>
<proxy bypassonlocal="true" usesystemdefault="false" />
</defaultProxy>
</system.net>
</configuration>
Using fiddler I can see that the above apparently works, because this results in fiddler not being able to capture the traffic.
All the following webservice calls on the client are handled within short time less than 1 sec.
What / How can I reduce the first calls delay ?
UPDATE
This wasn't due to problems with WCF this is a routing / DNS problem on our network in the company....
Background: We have a service installed at a remote site that has started failing to call an external webservice. According to the network\support engineers on site no proxy should be required, but when attempting to execute the WebRequest an exception is returned:
System.Net.WebException: The remote server returned an error: (407) Proxy Authentication Required.
The exception is relatively self-explanatory, but looking at the code, no Proxy is specified in the call to the WebRequest and no proxy is defined in the app.config file.
Referring to the MSDN documentation for WebRequest.Proxy:
"The IWebProxy object to use to proxy the request. The default value is set by calling the GlobalProxySelection.Select property."
and then referring to the documentation for GlobalProxySelection.Select:
"Gets or sets the global HTTP proxy."
And given that GlobalProxySelection.Select is not set anywhere in the application, where does the default value come from? And are there any other global config files where the global HTTP proxy may be set?
You have to set the proxy manually. You can do it by doing the following, if you want to use the Default system proxy. (Internet settings in windows)
myRequest.Proxy = WebRequest.GetSystemWebProxy();
You are getting the error because your network is blocking access to the server directly without using a proxy.
While this doesn't solve your problem directly, can I recommend trying a <defaultProxy /> element in your app.config / web.config under <system.net> with useDefaultCredentials="true" - this may well get your application authenticating through the proxy and therefore not requiring a special bypass rule at all.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.net>
<defaultProxy useDefaultCredentials="true" />
</system.net>
</configuration>
How to setup SMTPClient in ASP.net with C# to send email with provided proxy address ? or sending by detecting the system default proxy
I used the the following code in web.config but didnt work
<system.net>
<defaultProxy enabled="true">
<proxy bypassonlocal="False" proxyaddress="http://192.168.101.3:8080/" />
</defaultProxy>
</system.net>
You can't send SMTP email through an HTTP proxy server.
Speak to the person administering your Internet gateway/firewall to ask what host they want you to direct outbound email to.
Based on this article, you simply have to declare your proxy configuration into your Web.config and try to change the port:
If you are still having problems them try changing port number to 587
Edited my answer after your edit.
here is the sitution, i am testing on my localhost from my machine at home (no proxy server and windows default firewall) and retrieving api.flickr.com xml file, when I come to work (that uses an ISA server to connect) I get "remote server could not be resolved" so I added these lines to the web.config
<system.net>
<defaultProxy>
<proxy
usesystemdefault="False"
proxyaddress="http://localhost"
bypassonlocal="True"
/>
<bypasslist>
<add address="[a-z]+\.flickr\.com\.+" />
</bypasslist>
</defaultProxy>
</system.net>
that returns:System.Net.WebException: The remote server returned an error: (404) Not Found.
what went wrong? thanks
There are two possible scenarios here:
1: If you are building a client app (e.g. Console or WinForms) and want to access http://localhost using WebClient or HttpWebRequest without any intervening proxies, then bypassonlocal="True" should accomplish this. In other words, your app.config should look like this:
<defaultProxy>
<proxy
usesystemdefault="False"
bypassonlocal="True"
/>
</defaultProxy>
</system.net>
2: if, however, you're trying to get your ASP.NET app (running on http://localhost) to be able to correctly resolve URIs either with a proxy or without one, then you'll need to set up proxy info correctly in your web.config (or in machine.config so you won't have to change your app's web.config), so ASP.NET will know that you are running a proxy or not running one. Like this:
Home:
<defaultProxy>
<proxy
usesystemdefault="False"
bypassonlocal="True"
/>
</defaultProxy>
</system.net>
Work:
<defaultProxy>
<proxy
usesystemdefault="False"
proxyaddress="http://yourproxyserver:8080"
bypassonlocal="True"
/>
</defaultProxy>
</system.net>
It's also possible to use proxy auto-detection, to pick up settings from the registry, etc. but I've always shied away from those approaches for servers apps... too fragile.
BTW, if you find that things are configured correctly, and you still get the error, the first thing I'd recommend is to code up a quick test which manually sets the proxy before your WebClient/HttpWebRequest call, instead of relying on configuration to do it. Like this:
WebProxy proxyObject = new WebProxy("http://proxyserver:80/",true);
WebClient wc = new WebClient();
wc.Proxy = proxyObject;
string s = wc.DownloadString ("http://www.google.com");
If the requests don't go through your work proxy correctly even when you're using code, even if the proxy is correctly configured in your code, then the proxy itself may be the problem.
In WebClient to download data from local no issues but downloading from internet is problem so configure the following
In your Web.config add below lines and replace your Intenet proxy Address and port
<system.net>
<defaultProxy useDefaultCredentials="true" enabled="true">
<proxy usesystemdefault="False" proxyaddress="http://your proxy address:port" bypassonlocal="True" />
</defaultProxy>
<settings>
<servicePointManager expect100Continue="false" />
</settings> </system.net>
now your program logic work for downloading content from internet and public URLS.