Proxy - Access Denied

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Vladimir Rypacek

    Proxy - Access Denied

    Hi,
    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.Get DefaultProxy), create my own, pass credentials using just NetworkCredenti als, using CredentialsCach e... Nothing helped so far.

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

    ProbePX wspx = new ProbePX();

    // --- setting up the proxy

    wspx.Proxy = System.Net.WebP roxy.GetDefault Proxy();

    wspx.Proxy.Cred entials = System.Net.Cred entialCache.Def aultCredentials ;

    //wspx.Proxy.Cred entials = new System.Net.Netw orkCredential( txtPxUser.Text, txtPxPwd.Text, txtPxDomain.Tex t );

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

    System.Net.Cred entialCache cache = new System.Net.Cred entialCache();

    cache.Add(new Uri(wspx.Url), "Negotiate" , new System.Net.Netw orkCredential( txtAuthUser.Tex t, txtAuthPwd.Text , txtAuthDomain.T ext ));

    wspx.Credential s = cache;



    --
    Vlad
  • Vladimir Rypacek

    #2
    Re: Proxy - Access Denied

    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.WebP roxy.GetDefault Proxy();

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

    System.Net.Cred entialCache cache = new System.Net.Cred entialCache();

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

    cache.Add(((Web Proxy) this.Proxy).Add ress, "Kerberos", (System.Net.Net workCredential) System.Net.Cred entialCache.Def aultCredentials );

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

    cache.Add(new Uri("http://www.exis.cz"), "Basic", new System.Net.Netw orkCredential(" myuser", "mypwd", "mydomain") );

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

    ws.Proxy.Creden tials = cache;

    ws.Credentials = cache;

    // now you can call the WebService method

    ws.MyMethod();



    Comment

    Working...