Re: Windows authentication for web service client??



Kevin,
Thanks for responding, if you (or anyone) sees anything obviously wrong
with the below summary please let me know.

Thanks,
Dan

I have the following settings
Web config:
<authentication mode="Windows" />
<identity impersonate="true" />

IIS:
Anonymous access has been disabled and Integraged Security is the
only access that is enabled.

Client:
When calling the web service I make sure that I am passing the
defaultCredentials from the CredentialCache.

I hardcoded a credential using the following code and it works

Dim Response As System.Net.HttpWebResponse
Dim Request As HttpWebRequest = CType(WebRequest.Create(URI),
HttpWebRequest)
Dim MyCredentialCache = New System.Net.CredentialCache
MyCredentialCache.Add(New System.Uri(URI), "NTLM", _
New System.Net.NetworkCredential("myUserID", "myPassword", "myDomain"))

Request.Credentials = MyCredentialCache

make my http WEBDAV request here ...

Return (Response)

But this does not work:

Dim Response As System.Net.HttpWebResponse
Dim Request As HttpWebRequest = CType(WebRequest.Create(URI),
HttpWebRequest)

Request.Credentials = CredentialCache.DefaultCredentials
make my http WEBDAV request here ...

Return (Response)

Nor does this:

Dim impersonationContext As
System.Security.Principal.WindowsImpersonationContext
Dim currentWindowsIdentity As System.Security.Principal.WindowsIdentity

currentWindowsIdentity = CType(mobjUser.Identity,
System.Security.Principal.WindowsIdentity)
impersonationContext = currentWindowsIdentity.Impersonate()

Request.Credentials = CredentialCache.DefaultCredentials
Dim Response As System.Net.HttpWebResponse
Dim Request As HttpWebRequest = CType(WebRequest.Create(URI),
HttpWebRequest)

Request.Credentials = CredentialCache.DefaultCredentials

make my http WEBDAV request here ...

impersonationContext.Undo()

Return (Response)



"Kevin Yu" <koo9@xxxxxxxxxxx> wrote in message
news:u0yUSScQFHA.580@xxxxxxxxxxxxxxxxxxxxxxx
>
>
> "solex" <solex@xxxxxxxxxxxxx> wrote in message
> news:%23sSDjOSQFHA.244@xxxxxxxxxxxxxxxxxxxxxxx
>> I'm having a similar problem
>>
>> I have a web service that make a webDav request to Exchange.
>>
>> I have impersonation on but when I use the defaultCredentials in the web
>> services to make the webdav reqeust I get an Unauthorized 401 error. My
>> credentials have rights to make this request and I'm at my wits end
>> trying
>> to figure it out.
>>
>> The service works if I hard code my Network credentials in the service
>> but
>> does not otherwise.
>
> Hardcoded into your code? create a credential instead of using the
> defaultcredentials?
>
> I thought one can only create credential for "basic" or "digest"
> authentication mode.
>
> I try implicit impersonation, it won't work, even if you are
> impersonating,
> the web service has to
> put the credential on the soap message in order for it to be
> authenticated,
> because that's
> all the hosting service see when interacting with each other. don't want
> to
> do explicit impersonation.
>
>
> in .net 2.0, there will be a better support or even WSE 2.0, but this is
> not
> my options here.
> since if we were to use WSE 2.0, there will be a long process of paper
> work
> and testing and questioning.....
>
>
>
>
>
>>
>> Any help with this would also be appreciated.
>>
>> Thanks,
>> Dan
>>
>>
>> "Kevin Yu" <koo9@xxxxxxxxxxx> wrote in message
>> news:eOariLKQFHA.1476@xxxxxxxxxxxxxxxxxxxxxxx
>> > but the problem with impersonation in the code is after LogonUser()
> win32
>> > call, will the defaultcredentials be set to the new credentials then?
>> >
>> >
>> >
>> >
>> >
>> > "Kevin Yu" <koo9@xxxxxxxxxxx> wrote in message
>> > news:OEbaAMIQFHA.2356@xxxxxxxxxxxxxxxxxxxxxxx
>> >>I think impersonation will do , enable impersonation but don't
>> >>specified
>> >>the user, use code call the web service with a different
>> >>username/password.
>> >>
>> >>
>> >>
>> >> "Brock Allen" <ballen@xxxxxxxxxxxxxxxxx> wrote in message
>> >> news:453919632490103600068528@xxxxxxxxxxxxxxxxxxxxxxx
>> >>> The ASPNET account is a local account, so the other machine or domain
>> >>> wouldn't know about it. You can either run you web app under a
> different
>> >>> account, but that affects the rest of the code in there too. The
>> >>> other
>> >>> approach is to have a dedicated account (instead of using the current
>> >>> identity of ASPNET) that you can use to do the authentication and
>> >>> then
>> >>> use those credentials from the client.
>> >>>
>> >>> -Brock
>> >>> DevelopMentor
>> >>> http://staff.develop.com/ballen
>> >>>
>> >>>
>> >>>
>> >>>> hi all
>> >>>>
>> >>>> got a question here, a web service secure mode is set to "windows",
> on
>> >>>> the client side
>> >>>>
>> >>>> when supplying the credentials, it's like this:
>> >>>>
>> >>>> somewebservice.Authentication ssoAuth = new
>> >>>> somewebservice.Authentication();
>> >>>>
>> >>>> ssoAuth.PreAuthenticate = true;
>> >>>>
>> >>>> ssoAuth.Credentials = System.Net.CredentialCache.DefaultCredentials;
>> >>>>
>> >>>> from the info here
>> >>>>
>> >>>>
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref
>> >>>> /html/frlrfSystemNetCredentialCacheClassDefaultCredentialsTopic.asp
>> >>>>
>> >>>> the defaultcredential should supply the current security context
>> >>>> that
>> >>>> the client is running, but in my case the client is another web
>> >>>> service running
>> >>>>
>> >>>> on another server, now by default the account that the client(the
>> >>>> calling web service) is running under ASPNET account,
>> >>>>
>> >>>> so on the host(somewebservice), I should add the clientdomain\ASPNET
>> >>>> account into the windows account?
>> >>>>
>> >>>
>> >>>
>> >>>
>> >>
>> >>
>> >
>> >
>>
>>
>
>


.



Relevant Pages

  • Re: Code Stops Due to No Values In Query
    ... Dim PoseidonHotelProgram As Database ... Title = "DEPARTURES PENDING" ' Define title. ... Response = MsgBox ... Set Myset2 = db1.OpenRecordset("RESPEL ALL CHARGES") ...
    (microsoft.public.access.modulesdaovba)
  • Re: "/decompile /recompile"
    ... Response As Integer) ... 'Undo the combo-box before updating control value to "NewData" ... Dim ctl As Control ... Set rstShipVia = MyDB.OpenRecordset ...
    (comp.databases.ms-access)
  • Re: Requerying ComboBox in NotInList event
    ... Response As Integer) ... Dim rst As Recordset ... Set rst = CurrentDb.OpenRecordset ... Dim lngBlankFound As Long ...
    (comp.databases.ms-access)
  • Re: repli
    ... Private Sub Program_NotInList(NewData As String, Response As Integer) ... Dim cmd As ADODB.Command ... Dim strSQL As String, strMessage As String ...
    (microsoft.public.access.forms)
  • Re: repli
    ... Private Sub Program_NotInList(NewData As String, Response As Integer) ... Dim cmd As ADODB.Command ... Dim strSQL As String, strMessage As String ...
    (microsoft.public.access.forms)

Loading