How to CHANGE the Credentials for a web service proxy when using CredentialCache ?

Discussion in 'ASP .Net Web Services' started by Liviu Olaru, Jan 21, 2004.

  1. Liviu Olaru

    Liviu Olaru Guest

    Hi

    I'm trying to invoke a Web Service which is using BASIC authentication.
    Code for invoking:

    CredentialCache cc = new CredentialCache();
    //the network credential used to authenticate client
    NetworkCredential networkCred = new NetworkCredential("USERNAME",
    "PASSWORD");
    // the web service proxy
    WSProxy wsProxy = new WSProxy();

    //Add the network credential to the cache
    cc.Add(new Uri(wsProxy.Url), "Basic", networkCred);
    //Set the proxy credentials
    wsProxy.Credentials = cc;

    //call a method on proxy
    wsProxy.HellloWorld();

    I WANT TO USE THE SAME URL WITH DIFFERENT CREDENTIALS.( OR WITH NO
    CREDENTIAL )

    //so, now I try to remove the credential from cache
    cc.Remove(new Uri(wsProxy.Url), "Basic")

    If I remove the credential from CredentialCache, the subsequent calls to
    the web service will use the same credentials as for the first call, even
    the CredentialCache is empty !

    so, when I call

    WSProxy wsProxy2 = new WSProxy();
    wsProxy.Credentials = cc; // THIS LINE HAS NO EFFECT ! CAN BE COMMENTED
    OUT !
    wsProxy2.HelloWorld();

    the client is autenticated with the old credentials. (I wanted to get
    AccesDenied)

    It seems that, for the first call, the SoapHttpClientProtocol.Invoke
    method, in the case of a successful request, copies the credentials from
    CredentialCache and store them, per URL basis, in a internal store that is
    used for subsequent calls, even the new proxys have been setted different
    credentials.

    Thanks
    Liviu Olaru, Jan 21, 2004
    #1
    1. Advertising

  2. Liviu Olaru

    Jan Tielens Guest

    Try this:

    NetworkCredential networkCred = new NetworkCredential("USERNAME",
    "PASSWORD");

    // the web service proxy
    WSProxy wsProxy = new WSProxy();
    wsProxy.Credentials = networkCred;
    // do stuff

    WSProxy wsProxy2 = new WSProxy();
    // do stuff

    --
    Greetz

    Jan Tielens
    ________________________________
    Read my weblog: http://weblogs.asp.net/jan


    "Liviu Olaru" <> wrote in message
    news:#kf5eK$...
    > Hi
    >
    > I'm trying to invoke a Web Service which is using BASIC

    authentication.
    > Code for invoking:
    >
    > CredentialCache cc = new CredentialCache();
    > //the network credential used to authenticate client
    > NetworkCredential networkCred = new NetworkCredential("USERNAME",
    > "PASSWORD");
    > // the web service proxy
    > WSProxy wsProxy = new WSProxy();
    >
    > //Add the network credential to the cache
    > cc.Add(new Uri(wsProxy.Url), "Basic", networkCred);
    > //Set the proxy credentials
    > wsProxy.Credentials = cc;
    >
    > //call a method on proxy
    > wsProxy.HellloWorld();
    >
    > I WANT TO USE THE SAME URL WITH DIFFERENT CREDENTIALS.( OR WITH NO
    > CREDENTIAL )
    >
    > //so, now I try to remove the credential from cache
    > cc.Remove(new Uri(wsProxy.Url), "Basic")
    >
    > If I remove the credential from CredentialCache, the subsequent calls

    to
    > the web service will use the same credentials as for the first call, even
    > the CredentialCache is empty !
    >
    > so, when I call
    >
    > WSProxy wsProxy2 = new WSProxy();
    > wsProxy.Credentials = cc; // THIS LINE HAS NO EFFECT ! CAN BE

    COMMENTED
    > OUT !
    > wsProxy2.HelloWorld();
    >
    > the client is autenticated with the old credentials. (I wanted to get
    > AccesDenied)
    >
    > It seems that, for the first call, the SoapHttpClientProtocol.Invoke
    > method, in the case of a successful request, copies the credentials from
    > CredentialCache and store them, per URL basis, in a internal store that is
    > used for subsequent calls, even the new proxys have been setted different
    > credentials.
    >
    > Thanks
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    Jan Tielens, Jan 21, 2004
    #2
    1. Advertising

  3. Liviu Olaru

    Liviu Olaru Guest

    I have multiple URLs the client can authenticate to and I do not want to ask
    user for credentials again.

    Sorry, Jan, that I replied private.

    "Jan Tielens" <> wrote in message
    news:efsogP$...
    > Try this:
    >
    > NetworkCredential networkCred = new NetworkCredential("USERNAME",
    > "PASSWORD");
    >
    > // the web service proxy
    > WSProxy wsProxy = new WSProxy();
    > wsProxy.Credentials = networkCred;
    > // do stuff
    >
    > WSProxy wsProxy2 = new WSProxy();
    > // do stuff
    >
    > --
    > Greetz
    >
    > Jan Tielens
    > ________________________________
    > Read my weblog: http://weblogs.asp.net/jan
    >
    >
    > "Liviu Olaru" <> wrote in message
    > news:#kf5eK$...
    > > Hi
    > >
    > > I'm trying to invoke a Web Service which is using BASIC

    > authentication.
    > > Code for invoking:
    > >
    > > CredentialCache cc = new CredentialCache();
    > > //the network credential used to authenticate client
    > > NetworkCredential networkCred = new NetworkCredential("USERNAME",
    > > "PASSWORD");
    > > // the web service proxy
    > > WSProxy wsProxy = new WSProxy();
    > >
    > > //Add the network credential to the cache
    > > cc.Add(new Uri(wsProxy.Url), "Basic", networkCred);
    > > //Set the proxy credentials
    > > wsProxy.Credentials = cc;
    > >
    > > //call a method on proxy
    > > wsProxy.HellloWorld();
    > >
    > > I WANT TO USE THE SAME URL WITH DIFFERENT CREDENTIALS.( OR WITH NO
    > > CREDENTIAL )
    > >
    > > //so, now I try to remove the credential from cache
    > > cc.Remove(new Uri(wsProxy.Url), "Basic")
    > >
    > > If I remove the credential from CredentialCache, the subsequent

    calls
    > to
    > > the web service will use the same credentials as for the first call,

    even
    > > the CredentialCache is empty !
    > >
    > > so, when I call
    > >
    > > WSProxy wsProxy2 = new WSProxy();
    > > wsProxy.Credentials = cc; // THIS LINE HAS NO EFFECT ! CAN BE

    > COMMENTED
    > > OUT !
    > > wsProxy2.HelloWorld();
    > >
    > > the client is autenticated with the old credentials. (I wanted to

    get
    > > AccesDenied)
    > >
    > > It seems that, for the first call, the

    SoapHttpClientProtocol.Invoke
    > > method, in the case of a successful request, copies the credentials from
    > > CredentialCache and store them, per URL basis, in a internal store that

    is
    > > used for subsequent calls, even the new proxys have been setted

    different
    > > credentials.
    > >
    > > Thanks
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >

    >
    >
    Liviu Olaru, Jan 21, 2004
    #3
  4. Liviu Olaru

    Jan Tielens Guest

    Please look for follow-ups on this thread in the framework.webservices
    newsgroup...

    --
    Greetz

    Jan Tielens
    ________________________________
    Read my weblog: http://weblogs.asp.net/jan


    "Liviu Olaru" <> wrote in message
    news:#CKyXX$...
    >
    > I have multiple URLs the client can authenticate to and I do not want to

    ask
    > user for credentials again.
    >
    > Sorry, Jan, that I replied private.
    >
    > "Jan Tielens" <> wrote in message
    > news:efsogP$...
    > > Try this:
    > >
    > > NetworkCredential networkCred = new NetworkCredential("USERNAME",
    > > "PASSWORD");
    > >
    > > // the web service proxy
    > > WSProxy wsProxy = new WSProxy();
    > > wsProxy.Credentials = networkCred;
    > > // do stuff
    > >
    > > WSProxy wsProxy2 = new WSProxy();
    > > // do stuff
    > >
    > > --
    > > Greetz
    > >
    > > Jan Tielens
    > > ________________________________
    > > Read my weblog: http://weblogs.asp.net/jan
    > >
    > >
    > > "Liviu Olaru" <> wrote in message
    > > news:#kf5eK$...
    > > > Hi
    > > >
    > > > I'm trying to invoke a Web Service which is using BASIC

    > > authentication.
    > > > Code for invoking:
    > > >
    > > > CredentialCache cc = new CredentialCache();
    > > > //the network credential used to authenticate client
    > > > NetworkCredential networkCred = new NetworkCredential("USERNAME",
    > > > "PASSWORD");
    > > > // the web service proxy
    > > > WSProxy wsProxy = new WSProxy();
    > > >
    > > > //Add the network credential to the cache
    > > > cc.Add(new Uri(wsProxy.Url), "Basic", networkCred);
    > > > //Set the proxy credentials
    > > > wsProxy.Credentials = cc;
    > > >
    > > > //call a method on proxy
    > > > wsProxy.HellloWorld();
    > > >
    > > > I WANT TO USE THE SAME URL WITH DIFFERENT CREDENTIALS.( OR WITH NO
    > > > CREDENTIAL )
    > > >
    > > > //so, now I try to remove the credential from cache
    > > > cc.Remove(new Uri(wsProxy.Url), "Basic")
    > > >
    > > > If I remove the credential from CredentialCache, the subsequent

    > calls
    > > to
    > > > the web service will use the same credentials as for the first call,

    > even
    > > > the CredentialCache is empty !
    > > >
    > > > so, when I call
    > > >
    > > > WSProxy wsProxy2 = new WSProxy();
    > > > wsProxy.Credentials = cc; // THIS LINE HAS NO EFFECT ! CAN BE

    > > COMMENTED
    > > > OUT !
    > > > wsProxy2.HelloWorld();
    > > >
    > > > the client is autenticated with the old credentials. (I wanted to

    > get
    > > > AccesDenied)
    > > >
    > > > It seems that, for the first call, the

    > SoapHttpClientProtocol.Invoke
    > > > method, in the case of a successful request, copies the credentials

    from
    > > > CredentialCache and store them, per URL basis, in a internal store

    that
    > is
    > > > used for subsequent calls, even the new proxys have been setted

    > different
    > > > credentials.
    > > >
    > > > Thanks
    > > >
    > > >
    > > >
    > > >
    > > >
    > > >
    > > >
    > > >
    > > >
    > > >
    > > >

    > >
    > >

    >
    >
    Jan Tielens, Jan 21, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Craig
    Replies:
    1
    Views:
    10,982
    shobhaiyer
    Oct 3, 2007
  2. Tom
    Replies:
    0
    Views:
    157
  3. Liviu Olaru
    Replies:
    3
    Views:
    210
    Jan Tielens
    Jan 21, 2004
  4. Stan Rawrysz

    Credentials persist after CredentialCache.Remove()

    Stan Rawrysz, Apr 14, 2005, in forum: ASP .Net Security
    Replies:
    0
    Views:
    136
    Stan Rawrysz
    Apr 14, 2005
  5. Brad

    401 error accessing web service using credentials

    Brad, Dec 19, 2006, in forum: ASP .Net Web Services
    Replies:
    1
    Views:
    113
    Steven Cheng[MSFT]
    Dec 19, 2006
Loading...

Share This Page