+ Post New Thread
Results 1 to 11 of 11
Coding Thread, c# web service driving me insane in Coding and Web Development; I have the following in an application: Code: svc = new localhost.Service1(); svc.Credentials = CredentialCache.DefaultCredentials; svc is declared elsewhere as ...
  1. #1

    localzuk's Avatar
    Join Date
    Dec 2006
    Location
    Minehead
    Posts
    17,498
    Thank Post
    513
    Thanked 2,391 Times in 1,853 Posts
    Blog Entries
    24
    Rep Power
    819

    Angry c# web service driving me insane

    I have the following in an application:

    Code:
                    svc = new localhost.Service1();
                    svc.Credentials = CredentialCache.DefaultCredentials;
    svc is declared elsewhere as such:

    Code:
    private localhost.Service1 svc;
    Now, logic dicates that that service object will connect with the current user's credentials. Instead, I get an error message (as I put it in a try/catch block) stating 'Server was unable to process request. ---> Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'.'

    Why is it trying to log on with the anonymous account?!

    Any ideas, as this is driving me to the edge of sanity...

  2. #2

    sparkeh's Avatar
    Join Date
    May 2007
    Posts
    6,708
    Thank Post
    1,265
    Thanked 1,636 Times in 1,093 Posts
    Blog Entries
    22
    Rep Power
    503
    Hard to say without knowing what you are doing, but you aren't by chance trying to access a web server that uses an sql instance hosted on another server are you? (could be a long shot )

  3. #3
    bizzel's Avatar
    Join Date
    Jul 2007
    Location
    Cambridge
    Posts
    654
    Thank Post
    102
    Thanked 204 Times in 72 Posts
    Rep Power
    51
    Is the machine joined to the domain and is the logged-on account a domain user? Otherwise you'll get a blank set of credentials back.

  4. #4

    sparkeh's Avatar
    Join Date
    May 2007
    Posts
    6,708
    Thank Post
    1,265
    Thanked 1,636 Times in 1,093 Posts
    Blog Entries
    22
    Rep Power
    503
    Quote Originally Posted by sparkeh View Post
    Hard to say without knowing what you are doing, but you aren't by chance trying to access a web server that uses an sql instance hosted on another server are you? (could be a long shot )
    I say this as if this what you are doing it could be the 'double hop'. You can't pass credentials to one server to be passed on to another this way (or at least when I last looked)

    But you may be doing something completely different.

  5. #5

    localzuk's Avatar
    Join Date
    Dec 2006
    Location
    Minehead
    Posts
    17,498
    Thank Post
    513
    Thanked 2,391 Times in 1,853 Posts
    Blog Entries
    24
    Rep Power
    819
    Quote Originally Posted by sparkeh View Post
    Hard to say without knowing what you are doing, but you aren't by chance trying to access a web server that uses an sql instance hosted on another server are you? (could be a long shot )
    The SQL instance is on the same server (ie. the webservice and sql instance are on the server app1, and the client is on another machine).

    And the machine is domain joined and logged in too.

    I have come to the conclusion that I dislike web services in c#... ARGH!

  6. #6

    localzuk's Avatar
    Join Date
    Dec 2006
    Location
    Minehead
    Posts
    17,498
    Thank Post
    513
    Thanked 2,391 Times in 1,853 Posts
    Blog Entries
    24
    Rep Power
    819
    OK, the whole 'double hop' thing seems to be the issue - I've changed the connection string for SQL to localhost instead of the actual server name and it now 'works' (well, I now get a different message but I can work through that one I reckon).

  7. #7

    sparkeh's Avatar
    Join Date
    May 2007
    Posts
    6,708
    Thank Post
    1,265
    Thanked 1,636 Times in 1,093 Posts
    Blog Entries
    22
    Rep Power
    503
    Interesting...

    Hmm do you have a SPN registered for the SQL instance?

    So I think that the tcp connection to the server runs under LocalSystem account, if there is no SPN then it falls back to NTLM and the LocalSystem account inherits from System context rather than your user context and hence the anonymous login.

  8. #8

    localzuk's Avatar
    Join Date
    Dec 2006
    Location
    Minehead
    Posts
    17,498
    Thank Post
    513
    Thanked 2,391 Times in 1,853 Posts
    Blog Entries
    24
    Rep Power
    819
    Quote Originally Posted by sparkeh View Post
    Interesting...

    Hmm do you have a SPN registered for the SQL instance?

    So I think that the tcp connection to the server runs under LocalSystem account, if there is no SPN then it falls back to NTLM and the LocalSystem account inherits from System context rather than your user context and hence the anonymous login.
    To be honest, I have so little knowledge of MSSQL, I don't know what you mean. What is an SPN?

    I can understand the falling back part though.

  9. #9

    sparkeh's Avatar
    Join Date
    May 2007
    Posts
    6,708
    Thank Post
    1,265
    Thanked 1,636 Times in 1,093 Posts
    Blog Entries
    22
    Rep Power
    503
    Oh I'm no expert, just things I've picked up while dabbling

    SPN = Service Principal Name. Used for mutual authentication.
    Theres is an explanation here, the MS explanation here and guide to setting it up for SQL here.

  10. #10
    ajbritton's Avatar
    Join Date
    Jul 2005
    Location
    Wandsworth
    Posts
    1,632
    Thank Post
    23
    Thanked 75 Times in 45 Posts
    Rep Power
    34
    I've no experience of using c# or creating web services but I would not have expected a web service to use the 'current user credentials' unless you mean the credentials of the user issuing the request(?).

    If the service is running behind a web server (IIS) then I would expect it to default to use the anonymous logon account or the .NET account....

    Just a thought.

  11. #11

    sparkeh's Avatar
    Join Date
    May 2007
    Posts
    6,708
    Thank Post
    1,265
    Thanked 1,636 Times in 1,093 Posts
    Blog Entries
    22
    Rep Power
    503
    Quote Originally Posted by ajbritton View Post
    I've no experience of using c# or creating web services but I would not have expected a web service to use the 'current user credentials' unless you mean the credentials of the user issuing the request(?).

    If the service is running behind a web server (IIS) then I would expect it to default to use the anonymous logon account or the .NET account....

    Just a thought.
    Not true. Read this tech article about c# and DefaultCredentials

    The relevant bit:

    DefaultCredentials represents the system credentials for the current security context in which the application is running. For a client-side application, these are usually the Windows credentials (user name, password, and domain) of the user running the application. For ASP.NET applications, the default credentials are the user credentials of the logged-in user, or the user being impersonated.

SHARE:
+ Post New Thread

Similar Threads

  1. [Video] Insane Gamer
    By mattx in forum Jokes/Interweb Things
    Replies: 0
    Last Post: 18th July 2009, 11:50 AM
  2. Bulldog Broadband driving me insane!!
    By Number6 in forum Internet Related/Filtering/Firewall
    Replies: 30
    Last Post: 5th May 2009, 02:00 PM
  3. Web Host - Top notch customer service!
    By theeldergeek in forum Recommended Suppliers
    Replies: 3
    Last Post: 9th February 2009, 06:19 PM
  4. shortcuts : this is driving me insane...
    By kennysarmy in forum Windows
    Replies: 9
    Last Post: 28th January 2009, 08:12 PM
  5. Replies: 0
    Last Post: 30th September 2008, 03:24 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •