Connect to a WCF service (.svc) via a proxy (with username / password)
-
I've created a WCF service. I call it like this: ServiceClient client = new ServiceClient (); client.MyMethod(); So far so good on my machine. Now I've deployed it in our DMZ (whatever that is), and I can call it via an outside URL (so the request from my machine goes out to the Internet and then goes to our datacenter). But, we connect via a proxy to the Internet. I am not sure how that works, but I have to enter a proxy server in the connections, LAN settings section of Internet Explorer if I want to visit the Stack Overflow site. When I don't change the code, I get this error: The remote server returned an unexpected response: (407) Proxy Authentication Required ( The ISA Server requires authorization to fulfill the request. Access to the Web Proxy filter is denied. ). After googling, I found this code, but it leaves me with the same error. var b = client.Endpoint.Binding as System.ServiceModel.WSHttpBinding; b.ProxyAddress = new Uri("http://OURADDRESS.intern:8080"); b.BypassProxyOnLocal = false; b.UseDefaultWebProxy = false; client.ClientCredentials.UserName.UserName = @"DOMAIN\USERNAME"; client.ClientCredentials.UserName.Password = "myverysecretpassword";
-
Answer:
In such a case, using the default proxy should be enough: <configuration> <system.net> <defaultProxy useDefaultCredentials="true" /> </system.net> ... </configuration> In your binding, you must only ensure using the default proxy (should be enabled by default): b.UseDefaultWebProxy = true; In case of manually setting credentials, I believe that your proxy expect Windows credentials and because of that this should be used: client.ClientCredentials.Windows.ClientCredential.UserName = @"DOMAIN\USERNAME"; client.ClientCredentials.Windows.ClientCredential.Password = "myverysecretpassword";
Michel at Stack Overflow Visit the source
Related Q & A:
- Is it possible to allow a client/user to log into a Remote Desktop session using credentials other than their AD username/password? (for SSO?Best solution by Server Fault
- What is a WCF endpoint?Best solution by Stack Overflow
- How to call .aspx page from a web web service(service.svc?Best solution by Stack Overflow
- How to call the WCF service from silverlight application?Best solution by Stack Overflow
- How do you connect your laptop to your tv via HDMI cable?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.