401 While Accessing Web Service

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

    401 While Accessing Web Service

    I'm trying to access a c# web service from a web form.

    I set up the web reference proxy object as follows:

    proxy.PreAuthen ticate = true;
    proxy.Credentia ls = CredentialCache .DefaultCredent ials;


    but i get a 401 error. If I switch the IIS website from Integrated
    Windows Auth to Anonymous, it works... but i want it to use windows
    security.

    my web.config of the web form is set to imperonsate the logged on
    user, and i verified that's working by checking that
    this.User.Ident ity.Name is my domain user (which has access to the web
    service).

    Any ideas what i'm doing wrong? (btw, the web service is SSL if that
    makes a difference).

    Thanks!
  • Nirosh

    #2
    Re: 401 While Accessing Web Service

    Forms authentication works very well with web forms. Can you use it with web services? With some tricks - Yes. In fact in this article I am going to show how to do just that.


    check this and see..

    --
    L.W.C. Nirosh
    "Ben" <benm5678@gmail .comwrote in message
    news:b5138c67-4566-4595-84a2-336f6a582d1e@m7 3g2000hsh.googl egroups.com...
    I'm trying to access a c# web service from a web form.
    >
    I set up the web reference proxy object as follows:
    >
    proxy.PreAuthen ticate = true;
    proxy.Credentia ls = CredentialCache .DefaultCredent ials;
    >
    >
    but i get a 401 error. If I switch the IIS website from Integrated
    Windows Auth to Anonymous, it works... but i want it to use windows
    security.
    >
    my web.config of the web form is set to imperonsate the logged on
    user, and i verified that's working by checking that
    this.User.Ident ity.Name is my domain user (which has access to the web
    service).
    >
    Any ideas what i'm doing wrong? (btw, the web service is SSL if that
    makes a difference).
    >
    Thanks!

    Comment

    • Ben

      #3
      Re: 401 While Accessing Web Service

      On Apr 29, 2:30 pm, "Nirosh" <Nir...@News.Co mwrote:
      http://www.dotnetbips.com/articles/d...dfb-190d151103...
      >
      check this and see..
      >
      --
      L.W.C. Nirosh"Ben" <benm5...@gmail .comwrote in message
      >
      news:b5138c67-4566-4595-84a2-336f6a582d1e@m7 3g2000hsh.googl egroups.com...
      >
      >
      >
      I'm trying to access a c# web service from a web form.
      >
      I set up the web reference proxy object as follows:
      >
         proxy.PreAuthen ticate = true;
         proxy.Credentia ls = CredentialCache .DefaultCredent ials;
      >
      but i get a 401 error.  If I switch the IIS website from Integrated
      Windows Auth to Anonymous, it works... but i want it to use windows
      security.
      >
      my web.config of the web form is set to imperonsate the logged on
      user, and i verified that's working by checking that
      this.User.Ident ity.Name is my domain user (which has access to the web
      service).
      >
      Any ideas what i'm doing wrong? (btw, the web service is SSL if that
      makes a difference).
      >
      Thanks!- Hide quoted text -
      >
      - Show quoted text -
      thanks,
      anyway to do it without using web form authentication?

      the crazy thing is that if i fire up my web form from Visual Studio it
      works just fine and can access the web service, but if i publish it to
      another server and try from there I get the 401 (the site i'm
      publishing to is using 'intergrated windows auth') .

      Comment

      • Nirosh

        #4
        Re: 401 While Accessing Web Service

        okay, check WSE (Web Service Enhancement) to see how to improve the web
        service security..

        to avoid the dependacy with integrated authentication, create a new web site
        for your web service, that way it should work fine.

        --
        L.W.C. Nirosh

        "Ben" <benm5678@gmail .comwrote in message
        news:693f7c2e-35f2-4ace-b6d5-fb427b2547e6@b6 4g2000hsa.googl egroups.com...
        On Apr 29, 2:30 pm, "Nirosh" <Nir...@News.Co mwrote:
        http://www.dotnetbips.com/articles/d...dfb-190d151103...
        >
        check this and see..
        >
        --
        L.W.C. Nirosh"Ben" <benm5...@gmail .comwrote in message
        >
        news:b5138c67-4566-4595-84a2-336f6a582d1e@m7 3g2000hsh.googl egroups.com...
        >
        >
        >
        I'm trying to access a c# web service from a web form.
        >
        I set up the web reference proxy object as follows:
        >
        proxy.PreAuthen ticate = true;
        proxy.Credentia ls = CredentialCache .DefaultCredent ials;
        >
        but i get a 401 error. If I switch the IIS website from Integrated
        Windows Auth to Anonymous, it works... but i want it to use windows
        security.
        >
        my web.config of the web form is set to imperonsate the logged on
        user, and i verified that's working by checking that
        this.User.Ident ity.Name is my domain user (which has access to the web
        service).
        >
        Any ideas what i'm doing wrong? (btw, the web service is SSL if that
        makes a difference).
        >
        Thanks!- Hide quoted text -
        >
        - Show quoted text -
        thanks,
        anyway to do it without using web form authentication?

        the crazy thing is that if i fire up my web form from Visual Studio it
        works just fine and can access the web service, but if i publish it to
        another server and try from there I get the 401 (the site i'm
        publishing to is using 'intergrated windows auth') .


        Comment

        • Ben

          #5
          Re: 401 While Accessing Web Service

          On Apr 29, 3:03 pm, "Nirosh" <Nir...@News.Co mwrote:
          okay, check WSE (Web Service Enhancement) to see how to improve the web
          service security..
          >
          to avoid the dependacy with integrated authentication, create a new web site
          for your web service, that way it should work fine.
          >
          --
          L.W.C. Nirosh
          >
          "Ben" <benm5...@gmail .comwrote in message
          >
          news:693f7c2e-35f2-4ace-b6d5-fb427b2547e6@b6 4g2000hsa.googl egroups.com...
          On Apr 29, 2:30 pm, "Nirosh" <Nir...@News.Co mwrote:
          >
          >
          >
          >
          >>
          check this and see..
          >
          --
          L.W.C. Nirosh"Ben" <benm5...@gmail .comwrote in message
          >
          news:b5138c67-4566-4595-84a2-336f6a582d1e@m7 3g2000hsh.googl egroups.com...
          >
          I'm trying to access a c# web service from a web form.
          >
          I set up the web reference proxy object as follows:
          >
          proxy.PreAuthen ticate = true;
          proxy.Credentia ls = CredentialCache .DefaultCredent ials;
          >
          but i get a 401 error. If I switch the IIS website from Integrated
          Windows Auth to Anonymous, it works... but i want it to use windows
          security.
          >
          my web.config of the web form is set to imperonsate the logged on
          user, and i verified that's working by checking that
          this.User.Ident ity.Name is my domain user (which has access to the web
          service).
          >
          Any ideas what i'm doing wrong? (btw, the web service is SSL if that
          makes a difference).
          >
          Thanks!- Hide quoted text -
          >
          - Show quoted text -
          >
          thanks,
          anyway to do it without using web form authentication?
          >
          the crazy thing is that if i fire up my web form from Visual Studio it
          works just fine and can access the web service, but if i publish it to
          another server and try from there I get the 401 (the site i'm
          publishing to is using 'intergrated windows auth') .- Hide quoted text -
          >
          - Show quoted text -
          I'm using VS2008... is there WSE for that version? i can only find it
          for VS2005?

          is this the only way? i made C# web services before that were hosted
          on an IIS site with intergrated windows auth, but the client side was C
          ++ and i was able to pass current nt credentials without a problem....
          this is my first attempt where the client side is another c# web page.

          Comment

          • Nirosh

            #6
            Re: 401 While Accessing Web Service

            I am not sure whether this is the only way.. When you say it worked with C++
            and now is not working with aspx/c# web site, that is interesting..

            The WSE 3.0 should work fine with framework 3.0/3.5. But if you want it to
            work with VSS 2008 IDE then you need to trick it.

            e.g.:-

            But I din't do this.. so please do it with extra care..

            --
            L.W.C. Nirosh

            "Ben" <benm5678@gmail .comwrote in message
            news:d424f374-f2ae-4691-bfa5-a2186116e223@2g 2000hsn.googleg roups.com...
            On Apr 29, 3:03 pm, "Nirosh" <Nir...@News.Co mwrote:
            okay, check WSE (Web Service Enhancement) to see how to improve the web
            service security..
            >
            to avoid the dependacy with integrated authentication, create a new web
            site
            for your web service, that way it should work fine.
            >
            --
            L.W.C. Nirosh
            >
            "Ben" <benm5...@gmail .comwrote in message
            >
            news:693f7c2e-35f2-4ace-b6d5-fb427b2547e6@b6 4g2000hsa.googl egroups.com...
            On Apr 29, 2:30 pm, "Nirosh" <Nir...@News.Co mwrote:
            >
            >
            >
            >
            >>
            check this and see..
            >
            --
            L.W.C. Nirosh"Ben" <benm5...@gmail .comwrote in message
            >
            news:b5138c67-4566-4595-84a2-336f6a582d1e@m7 3g2000hsh.googl egroups.com...
            >
            I'm trying to access a c# web service from a web form.
            >
            I set up the web reference proxy object as follows:
            >
            proxy.PreAuthen ticate = true;
            proxy.Credentia ls = CredentialCache .DefaultCredent ials;
            >
            but i get a 401 error. If I switch the IIS website from Integrated
            Windows Auth to Anonymous, it works... but i want it to use windows
            security.
            >
            my web.config of the web form is set to imperonsate the logged on
            user, and i verified that's working by checking that
            this.User.Ident ity.Name is my domain user (which has access to the web
            service).
            >
            Any ideas what i'm doing wrong? (btw, the web service is SSL if that
            makes a difference).
            >
            Thanks!- Hide quoted text -
            >
            - Show quoted text -
            >
            thanks,
            anyway to do it without using web form authentication?
            >
            the crazy thing is that if i fire up my web form from Visual Studio it
            works just fine and can access the web service, but if i publish it to
            another server and try from there I get the 401 (the site i'm
            publishing to is using 'intergrated windows auth') .- Hide quoted text -
            >
            - Show quoted text -
            I'm using VS2008... is there WSE for that version? i can only find it
            for VS2005?

            is this the only way? i made C# web services before that were hosted
            on an IIS site with intergrated windows auth, but the client side was C
            ++ and i was able to pass current nt credentials without a problem....
            this is my first attempt where the client side is another c# web page.


            Comment

            • Ben

              #7
              Re: 401 While Accessing Web Service

              On Apr 29, 3:32 pm, "Nirosh" <Nir...@News.Co mwrote:
              I am not sure whether this is the only way.. When you say it worked with C++
              and now is not working with aspx/c# web site, that is interesting..
              >
              The WSE 3.0 should work fine with framework 3.0/3.5. But if you want it to
              work with VSS 2008 IDE then you need to trick it.
              >
              e.g.:-http://devlicio.us/blogs/derik_whittaker/archive/2008/04/03/wse-3-0-s...
              But I din't do this.. so please do it with extra care..
              >
              --
              L.W.C. Nirosh
              >
              "Ben" <benm5...@gmail .comwrote in message
              >
              news:d424f374-f2ae-4691-bfa5-a2186116e223@2g 2000hsn.googleg roups.com...
              On Apr 29, 3:03 pm, "Nirosh" <Nir...@News.Co mwrote:
              >
              >
              >
              >
              >
              okay, check WSE (Web Service Enhancement) to see how to improve the web
              service security..
              >
              to avoid the dependacy with integrated authentication, create a new web
              site
              for your web service, that way it should work fine.
              >
              --
              L.W.C. Nirosh
              >
              "Ben" <benm5...@gmail .comwrote in message
              >
              news:693f7c2e-35f2-4ace-b6d5-fb427b2547e6@b6 4g2000hsa.googl egroups.com...
              On Apr 29, 2:30 pm, "Nirosh" <Nir...@News.Co mwrote:
              >>
              check this and see..
              >
              --
              L.W.C. Nirosh"Ben" <benm5...@gmail .comwrote in message
              >
              >news:b5138c6 7-4566-4595-84a2-336f6a582d1e@m7 3g2000hsh.googl egroups.com....
              >
              I'm trying to access a c# web service from a web form.
              >
              I set up the web reference proxy object as follows:
              >
              proxy.PreAuthen ticate = true;
              proxy.Credentia ls = CredentialCache .DefaultCredent ials;
              >
              but i get a 401 error. If I switch the IIS website from Integrated
              Windows Auth to Anonymous, it works... but i want it to use windows
              security.
              >
              my web.config of the web form is set to imperonsate the logged on
              user, and i verified that's working by checking that
              this.User.Ident ity.Name is my domain user (which has access to the web
              service).
              >
              Any ideas what i'm doing wrong? (btw, the web service is SSL if that
              makes a difference).
              >
              Thanks!- Hide quoted text -
              >
              - Show quoted text -
              >
              thanks,
              anyway to do it without using web form authentication?
              >
              the crazy thing is that if i fire up my web form from Visual Studio it
              works just fine and can access the web service, but if i publish it to
              another server and try from there I get the 401 (the site i'm
              publishing to is using 'intergrated windows auth') .- Hide quoted text -
              >
              - Show quoted text -
              >
              I'm using VS2008... is there WSE for that version? i can only find it
              for VS2005?
              >
              is this the only way?  i made C# web services before that were hosted
              on an IIS site with intergrated windows auth, but the client side was C
              ++ and i was able to pass current nt credentials without a problem....
              this is my first attempt where the client side is another c# web page.- Hide quoted text -
              >
              - Show quoted text -
              I switched the project to VS2005 just to test and enabled WSE 3.0
              support -- is there any additional settings i need to change since it
              still throws the same error...

              Comment

              • Nirosh

                #8
                Re: 401 While Accessing Web Service

                You need to get the web service configure into a another web site, then you
                can remove the integrated authentication just for that web site.. then your
                web service will be vulnerable, so to improve security use the WSE..

                just converting the project to 2005 and enable wse won't do any good. as the
                webservice is still having integrated security..

                --
                L.W.C. Nirosh
                "Ben" <benm5678@gmail .comwrote in message
                news:4878e99d-ef98-41e8-aaf5-faafd1238f3a@k3 7g2000hsf.googl egroups.com...
                On Apr 29, 3:32 pm, "Nirosh" <Nir...@News.Co mwrote:
                I am not sure whether this is the only way.. When you say it worked with
                C++
                and now is not working with aspx/c# web site, that is interesting..
                >
                The WSE 3.0 should work fine with framework 3.0/3.5. But if you want it to
                work with VSS 2008 IDE then you need to trick it.
                >
                e.g.:-http://devlicio.us/blogs/derik_whittaker/archive/2008/04/03/wse-3-0-s...
                But I din't do this.. so please do it with extra care..
                >
                --
                L.W.C. Nirosh
                >
                "Ben" <benm5...@gmail .comwrote in message
                >
                news:d424f374-f2ae-4691-bfa5-a2186116e223@2g 2000hsn.googleg roups.com...
                On Apr 29, 3:03 pm, "Nirosh" <Nir...@News.Co mwrote:
                >
                >
                >
                >
                >
                okay, check WSE (Web Service Enhancement) to see how to improve the web
                service security..
                >
                to avoid the dependacy with integrated authentication, create a new web
                site
                for your web service, that way it should work fine.
                >
                --
                L.W.C. Nirosh
                >
                "Ben" <benm5...@gmail .comwrote in message
                >
                news:693f7c2e-35f2-4ace-b6d5-fb427b2547e6@b6 4g2000hsa.googl egroups.com...
                On Apr 29, 2:30 pm, "Nirosh" <Nir...@News.Co mwrote:
                >>
                check this and see..
                >
                --
                L.W.C. Nirosh"Ben" <benm5...@gmail .comwrote in message
                >
                >news:b5138c6 7-4566-4595-84a2-336f6a582d1e@m7 3g2000hsh.googl egroups.com...
                >
                I'm trying to access a c# web service from a web form.
                >
                I set up the web reference proxy object as follows:
                >
                proxy.PreAuthen ticate = true;
                proxy.Credentia ls = CredentialCache .DefaultCredent ials;
                >
                but i get a 401 error. If I switch the IIS website from Integrated
                Windows Auth to Anonymous, it works... but i want it to use windows
                security.
                >
                my web.config of the web form is set to imperonsate the logged on
                user, and i verified that's working by checking that
                this.User.Ident ity.Name is my domain user (which has access to the
                web
                service).
                >
                Any ideas what i'm doing wrong? (btw, the web service is SSL if that
                makes a difference).
                >
                Thanks!- Hide quoted text -
                >
                - Show quoted text -
                >
                thanks,
                anyway to do it without using web form authentication?
                >
                the crazy thing is that if i fire up my web form from Visual Studio it
                works just fine and can access the web service, but if i publish it to
                another server and try from there I get the 401 (the site i'm
                publishing to is using 'intergrated windows auth') .- Hide quoted text -
                >
                - Show quoted text -
                >
                I'm using VS2008... is there WSE for that version? i can only find it
                for VS2005?
                >
                is this the only way? i made C# web services before that were hosted
                on an IIS site with intergrated windows auth, but the client side was C
                ++ and i was able to pass current nt credentials without a problem....
                this is my first attempt where the client side is another c# web page.-
                Hide quoted text -
                >
                - Show quoted text -
                I switched the project to VS2005 just to test and enabled WSE 3.0
                support -- is there any additional settings i need to change since it
                still throws the same error...


                Comment

                • Ben

                  #9
                  Re: 401 While Accessing Web Service

                  On Apr 29, 4:11 pm, "Nirosh" <Nir...@News.Co mwrote:
                  You need to get the web service configure into a another web site, then you
                  can remove the integrated authentication just for that web site.. then your
                  web service will be vulnerable, so to improve security use the WSE..
                  >
                  just converting the project to 2005 and enable wse won't do any good. as the
                  webservice is still having integrated security..
                  >
                  --
                  L.W.C. Nirosh"Ben" <benm5...@gmail .comwrote in message
                  >
                  news:4878e99d-ef98-41e8-aaf5-faafd1238f3a@k3 7g2000hsf.googl egroups.com...
                  On Apr 29, 3:32 pm, "Nirosh" <Nir...@News.Co mwrote:
                  >
                  >
                  >
                  >
                  >
                  I am not sure whether this is the only way.. When you say it worked with
                  C++
                  and now is not working with aspx/c# web site, that is interesting..
                  >
                  The WSE 3.0 should work fine with framework 3.0/3.5. But if you want it to
                  work with VSS 2008 IDE then you need to trick it.
                  >
                  e.g.:-http://devlicio.us/blogs/derik_whittaker/archive/2008/04/03/wse-3-0-s...
                  But I din't do this.. so please do it with extra care..
                  >
                  --
                  L.W.C. Nirosh
                  >
                  "Ben" <benm5...@gmail .comwrote in message
                  >
                  news:d424f374-f2ae-4691-bfa5-a2186116e223@2g 2000hsn.googleg roups.com...
                  On Apr 29, 3:03 pm, "Nirosh" <Nir...@News.Co mwrote:
                  >
                  okay, check WSE (Web Service Enhancement) to see how to improve the web
                  service security..
                  >
                  to avoid the dependacy with integrated authentication, create a new web
                  site
                  for your web service, that way it should work fine.
                  >
                  --
                  L.W.C. Nirosh
                  >
                  "Ben" <benm5...@gmail .comwrote in message
                  >
                  >news:693f7c2 e-35f2-4ace-b6d5-fb427b2547e6@b6 4g2000hsa.googl egroups.com....
                  On Apr 29, 2:30 pm, "Nirosh" <Nir...@News.Co mwrote:
                  >>
                  check this and see..
                  >
                  --
                  L.W.C. Nirosh"Ben" <benm5...@gmail .comwrote in message
                  >
                  news:b5138c67-4566-4595-84a2-336f6a582d1e@m7 3g2000hsh.googl egroups.com...
                  >
                  I'm trying to access a c# web service from a web form.
                  >
                  I set up the web reference proxy object as follows:
                  >
                  proxy.PreAuthen ticate = true;
                  proxy.Credentia ls = CredentialCache .DefaultCredent ials;
                  >
                  but i get a 401 error. If I switch the IIS website from Integrated
                  Windows Auth to Anonymous, it works... but i want it to use windows
                  security.
                  >
                  my web.config of the web form is set to imperonsate the logged on
                  user, and i verified that's working by checking that
                  this.User.Ident ity.Name is my domain user (which has access to the
                  web
                  service).
                  >
                  Any ideas what i'm doing wrong? (btw, the web service is SSL if that
                  makes a difference).
                  >
                  Thanks!- Hide quoted text -
                  >
                  - Show quoted text -
                  >
                  thanks,
                  anyway to do it without using web form authentication?
                  >
                  the crazy thing is that if i fire up my web form from Visual Studio it
                  works just fine and can access the web service, but if i publish it to
                  another server and try from there I get the 401 (the site i'm
                  publishing to is using 'intergrated windows auth') .- Hide quoted text-
                  >
                  - Show quoted text -
                  >
                  I'm using VS2008... is there WSE for that version? i can only find it
                  for VS2005?
                  >
                  is this the only way? i made C# web services before that were hosted
                  on an IIS site with intergrated windows auth, but the client side was C
                  ++ and i was able to pass current nt credentials without a problem....
                  this is my first attempt where the client side is another c# web page.-
                  Hide quoted text -
                  >
                  - Show quoted text -
                  >
                  I switched the project to VS2005 just to test and enabled WSE 3.0
                  support -- is there any additional settings i need to change since it
                  still throws the same error...- Hide quoted text -
                  >
                  - Show quoted text -
                  so are u saying I cannot use integrated security on a WS?

                  btw, it works fine if my client is a C# windows form (instead of a web
                  form)... so I think this shows the WS is okay... it's just there's
                  something i'm missing on the web form to make it work... but
                  everywhere i read i see they just say to set the Credentials param and
                  i did that already.

                  Comment

                  • =?Utf-8?B?YnJ1Y2UgYmFya2Vy?=

                    #10
                    RE: 401 While Accessing Web Service

                    you are hitting the one hop rule with nt creditals. it should work if you hit
                    the web site locally, but not from another computer.

                    to do this you have two options:

                    1) switch to basic, which will give the web server a primary token it can
                    use to access a second server.
                    2) switch to kerberos and enable server credentials delegation.


                    -- bruce (sqlwork.com)


                    "Ben" wrote:
                    I'm trying to access a c# web service from a web form.
                    >
                    I set up the web reference proxy object as follows:
                    >
                    proxy.PreAuthen ticate = true;
                    proxy.Credentia ls = CredentialCache .DefaultCredent ials;
                    >
                    >
                    but i get a 401 error. If I switch the IIS website from Integrated
                    Windows Auth to Anonymous, it works... but i want it to use windows
                    security.
                    >
                    my web.config of the web form is set to imperonsate the logged on
                    user, and i verified that's working by checking that
                    this.User.Ident ity.Name is my domain user (which has access to the web
                    service).
                    >
                    Any ideas what i'm doing wrong? (btw, the web service is SSL if that
                    makes a difference).
                    >
                    Thanks!
                    >

                    Comment

                    • Ben

                      #11
                      Re: 401 While Accessing Web Service

                      On Apr 29, 5:58 pm, bruce barker
                      <brucebar...@di scussions.micro soft.comwrote:
                      you are hitting the one hop rule with nt creditals. it should work if you hit
                      the web site locally, but not from another computer.
                      >
                      to do this you have two options:
                      >
                      1) switch to basic, which will give the web server a primary token it can
                      use to access a second server.
                      2) switch to kerberos and enable server credentials delegation.
                      >
                      -- bruce (sqlwork.com)
                      >
                      >
                      >
                      "Ben" wrote:
                      I'm trying to access a c# web service from a web form.
                      >
                      I set up the web reference proxy object as follows:
                      >
                          proxy.PreAuthen ticate = true;
                          proxy.Credentia ls = CredentialCache .DefaultCredent ials;
                      >
                      but i get a 401 error.  If I switch the IIS website from Integrated
                      Windows Auth to Anonymous, it works... but i want it to use windows
                      security.
                      >
                      my web.config of the web form is set to imperonsate the logged on
                      user, and i verified that's working by checking that
                      this.User.Ident ity.Name is my domain user (which has access to the web
                      service).
                      >
                      Any ideas what i'm doing wrong? (btw, the web service is SSL if that
                      makes a difference).
                      >
                      Thanks!- Hide quoted text -
                      >
                      - Show quoted text -
                      for option 1 it sounds like i'll need to know the user/pwd which i
                      won't...

                      option 2 sounds interesting... is this a complicated thing to setup?
                      i've been trying to search on the issue and haven't found a good
                      description on how to set it up yet... if anyone has any further info
                      on it i'd really appreciate it!

                      Thanks!!!

                      Comment

                      Working...