By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,086 Members | 1,875 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,086 IT Pros & Developers. It's quick & easy.

Proxy - Access Denied

P: n/a
I've got strange error on computer which is accessing web-service thrugh proxy.

Scenario 1
- the web-service does not require authentication (Anonymous access is allowed)
- client works fine

Scenario 2
- web-service requires authentication (Intergrated Win. auth / Basic auth.)
- client fails on 401 : Access Denied even though correct credentials are supplied

Scenario 3
- same as Scenario 2, but from client who's not using proxy
- client works fine

It seems as if just the combination of proxy & site which requires authentication was creating the problem.

I tried everything, wirh with default proxy (System.Net.GetDefaultProxy), create my own, pass credentials using just NetworkCredentials, using CredentialsCache... Nothing helped so far.

This is sample code:
// --- my web-service proxy

ProbePX wspx = new ProbePX();

// --- setting up the proxy

wspx.Proxy = System.Net.WebProxy.GetDefaultProxy();

wspx.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;

//wspx.Proxy.Credentials = new System.Net.NetworkCredential( txtPxUser.Text, txtPxPwd.Text, txtPxDomain.Text );

// --- setting up the credentials for the web-service

System.Net.CredentialCache cache = new System.Net.CredentialCache();

cache.Add(new Uri(wspx.Url), "Negotiate", new System.Net.NetworkCredential( txtAuthUser.Text, txtAuthPwd.Text, txtAuthDomain.Text ));

wspx.Credentials = cache;

Nov 21 '05 #1
Share this Question
Share on Google+
1 Reply

P: n/a
Ok, I finally figured it out. Seems like the credentials have to be specified not only for the web-service, but also for the proxy (i.e. they have to "share" them). I think it's a bug in WSE2, but this fixes it...

// create sample web-service instance

SampleWS ws = new SampleWS();

// get default proxy and assign it to the WebService. Alternatively, you can replace this with manual WebProxy creation.

ws.Proxy = System.Net.WebProxy.GetDefaultProxy();

// create credentials cache - it will hold both, the WebProxy credentials and the WebService credentials too

System.Net.CredentialCache cache = new System.Net.CredentialCache();

// add default credentials for Proxy (notice the authType = 'Kerberos' !) Other types are 'Basic', 'Digest', 'Negotiate', 'NTLM'

cache.Add(((WebProxy) this.Proxy).Address, "Kerberos", (System.Net.NetworkCredential) System.Net.CredentialCache.DefaultCredentials);

// add credentials needed for the WebService (fill your own values here)

cache.Add(new Uri(""), "Basic", new System.Net.NetworkCredential("myuser", "mypwd", "mydomain"));

// assign the credentials to both, the Proxy and WebService too

ws.Proxy.Credentials = cache;

ws.Credentials = cache;

// now you can call the WebService method


Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.