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>
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.
I want to make a request to a resource (that resource is behind a proxy). I have the proxy address and the port as well. I have tried with NetworkCredentialn no success, with CacheCredentials no success. WebException is:
ProtocolError
The remote server returned an error: (407) Proxy Authentification Required
I always get error at this line:
WebResponse response = request.GetResponse();
I have already done this:
Package manager in Visual Studio 2015 "407 (Proxy Authentication Required)"
I tried to configure my App.config file
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.net>
<defaultProxy useDefaultCredentials="true" />
</system.net>
</configuration>
From our corporate network, we usually employ this code:
WebProxy proxy = new WebProxy("http://your.proxy.server:8080", true);
proxy.Credentials = new NetworkCredential("user", "password");
WebRequest.DefaultWebProxy = proxy;
The idea is you put this code somewhere at the beginning of your program (or in the App start if you're on IIS) and then every single request will take the default proxy configuration.
No change in web.config is required. AFAICT, in web.config you cannot set the credentials.
In my experience, it works also for web services and WCF communications.
I'm trying to call web service for few hours.
I have added clientaccesspolicy.xml:
<?xml version="1.0" encoding="utf-8"?>
<access-policy>
<cross-domain-access>
<policy>
<allow-from http-request-headers="*">
<domain uri="*"/>
</allow-from>
<grant-to>
<resource path="/" include-subpaths="true"/>
</grant-to>
</policy>
</cross-domain-access>
</access-policy>
and crossdomain.xml:
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-http-request-headers-from domain="*" headers="SOAPAction,Content-Type"/>
</cross-domain-policy>
to root directory of my web site.
Web service is called from IIS, and it's working here.
But when I'm trying to call my wcf web service from silverlight application I get this error:
The remote server returned an error: NotFound.
This is log from Fiddler:
a:InternalServiceFaultThe server was unable to process the request due to
an internal error. For more information about the error, either turn
on IncludeExceptionDetailInFaults (either from
ServiceBehaviorAttribute or from the <serviceDebug>
configuration behavior) on the server in order to send the exception
information back to the client, or turn on tracing as per the
Microsoft .NET Framework 3.0 SDK documentation and inspect the server
trace logs.
This is code, when I get an error:
public int EndUserExist(System.IAsyncResult result) {
object[] _args = new object[0];
int _result = ((int)(base.EndInvoke("UserExist", _args, result))); //Here
return _result;
}
What am I doing wrong?
Look in your web.config for this text: IncludeExceptionDetailInFaults
set that to true. Then run your service request again and watch Fiddler this time it will tell you what you need to know.
May be anything from a SQL error to a null reference. :-)
All right ;)
Now it's working.
I turned on debug in web.config so I got exception message in Fiddler.
I need to set identity user in pool on IIS for sql database.
In your mobile device, go to wifi settings and edit current wifi connection.
Set proxy "Automatically detect settings".
Im trying to call an Axis Ws that has NTLM Security in it, im using BasicHttpBinding, the problem is that if i call it i get an error saying:
The server did not provide a meaningful reply; this might be caused by a contract mismatch, a premature session shutdown or an internal server error.
I dont have any access to that server so i cannot look at how it is configured.
But if the call a Get with HttpWebRequest to that WS with my credentials too, and then call the ws it works fine.
Any idea on what i am missing?
Looks like you need to pass your credentials when calling the web service. Have you tried using impersonation or passing your credentials (like so)?
SomeService client = new SomeService();
client.Credentials = new NetworkCredentials("username","password");
...
You may want to check the following settings are set on your webserver web.config
<system.web>
<identity impersonate="true" />
<authentication mode="Windows">
</system.web>
I have spent two hours on this error "HTTP status 407: Proxy authentication required Error " when calling a web service, my code is like following
WebProxy oWebProxy = new System.Net.WebProxy(ProxyServer, ProxyPort);
oWebProxy.Credentials = new NetworkCredential(ProxyUser,ProxyPassword,ProxyDomain);
oserv.Proxy = oWebProxy;
oserv.Credentials = new NetworkCredential(theusername, thepassword);
I have verified that the proxy address, user id password are all correct, and I could access the web service thru the IE in same pc, but when I run the code with VS, the error keeps popup.
I have tried the UserDefaultCredentials=true as well, but no luck.
Any idea?
Popping a<defaultProxy /> element into in app.config / web.config under <system.net> with useDefaultCredentials="true" may well do the job.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.net>
<defaultProxy useDefaultCredentials="true" />
</system.net>
</configuration>
Try to run the application in on same network where the webservice is installed