Trying to pass NetworkCredential to WebService

Ask a Question related to ASP.NET Web Services, Design and Development.

  1. #1

    Default Trying to pass NetworkCredential to WebService

    Hello,

    I am running W2k3, Visual Studio 2003, Framework version 1.1.4322. I have
    one simple asp.net web service and one simple asp.net web app. When I run
    the web service directly ([url]http://localhost/mywebservice/Service.asmx[/url])
    everything works fine. When I try to call the web service from my web app I
    always get the same error:
    System.Net.WebException: The request failed with HTTP status 401:
    Unauthorized

    I also see a new event in my System event log:
    Source: Kerberos

    Event Id: 4

    The kerberos client received a KRB_AP_ERR_MODIFIED error from the server
    host/mbell2.<mydomain>. The target name used was HTTP/mbell2.<mydomain>.
    This indicates that the password used to encrypt the kerberos service ticket
    is different than that on the target server. Commonly, this is due to
    identically named machine accounts in the target realm (<mydomain>), and
    the client realm. Please contact your system administrator.


    I have searched Google Groups what seems like 100 times and I have tried
    (what seems like) everything.

    Here is my web method:
    // Security commented out.

    // Security works when running directly

    // from [url]http://localhost/[/url]...

    //[PrincipalPermission(SecurityAction.Demand,
    Role=@"MyDomain\RoleMapWS_Admins")]

    [WebMethod]

    public bool EnableUser(int userId)

    {

    try

    {

    (new UserDAO()).EnableAccount(userId);



    return true;

    }

    catch (Exception ex)

    {

    throw;

    }

    }



    Here is my web app:

    // Private to class

    private Open.WebServices.RoleMap.Service ws = new
    Open.WebServices.RoleMap.Service();

    ...

    private void Button1_Click(object sender, System.EventArgs e)

    {

    ICredentials cred = new NetworkCredential(@"mbell", "open",
    "MyDomain");



    ws.PreAuthenticate = true;

    // I have tried

    // ws.Credentials = cred;

    ws.Credentials = cred.GetCredential(new Uri(ws.Url), "");



    try

    {

    ws.EnableUser(2);

    }

    catch (Exception ex)

    {

    throw;

    }

    }



    Thank you for your help,



    Marshall


    Marshall Guest

  2. Similar Questions and Discussions

    1. Pass Date to Webservice
      Trying to pass a date to a webservice using a String formatted as '2007-10-30T12:00:00'. Webservice is set up expecting date as a Calendar. Get a...
    2. How do you pass an array of structures to webservice?
      Hello, Does anyone have an example of how to pass an array of strings (ie purchase Id's) from CF to a web service (like weblogic), and then...
    3. How do you pass an complex data types to webservice?
      Hello, I have gone through the simple CFC web services examples where you invoke a call to a web service with a methods and parameters.... but...
    4. How to pass <br> string to webservice ?
      Greetings, I have asp.net page with a textbox. This textbox is used to pass values(mainly strings) to VB.NET webservice using...
    5. Using .NET Client To Pass ArrayList To Java WebService
      "Ashish" <asdd@hotmail.com> wrote in message news:O$Hbp9mQDHA.704@tk2msftngp13.phx.gbl... yes. solution: Don't use types that are platform...
  3. #2

    Default RE: Trying to pass NetworkCredential to WebService

    Hello Marshall,

    Did your Web service use Windows integrated authentication and disable
    anonymous access? For such a web service, we need to pass a valid
    credential to it. for example:

    localhost.Service1 myProxy = new localhost.Service1();
    myProxy.Credentials = System.Net.CredentialCache.DefaultCredentials;

    or

    localhost.Service1 myProxy = new localhost.Service1();
    myProxy.Credentials = new System.Net.NetworkCredential("domain\username",
    "password", "");

    for details, you can refer to:

    [url]http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q813834[/url]

    Luke


    [MSFT] Guest

  4. #3

    Default Re: Trying to pass NetworkCredential to WebService

    Thanks Luke,

    Yes, the web service is set to use Integrated authentication and anonymous
    access is disabled.

    My code was passing credientials like you illustrated. The link you
    attached guided me to another kb article which solved my problem.

    [url]http://support.microsoft.com/kb/811318/EN-US/[/url]

    I changed my code to use the CredentialCache class and it worked like this:
    localhost.Service ws = new localhost.Service();

    System.Net.CredentialCache cache = new System.Net.CredentialCache();
    cache.Add( new Uri(ws.Url), "Negotiate", new
    System.Net.NetworkCredential("userName", "password", "domain"));
    ws.Credentials = cache;

    Response.Write(ws.HelloWorld());

    Thanks,

    Marshall


    Marshall Guest

  5. #4

    Default Re: Trying to pass NetworkCredential to WebService

    Actually, my statement was incorrect. The problem was that my web service
    was running in its own application pool with an identity of a domain
    account. So this still is a problem because my web service needs to run in
    its own pool because I tie Sql Server permissions to its identity.

    "Marshall" <marshall@newsgroup.nospam> wrote in message
    news:%23GmyXSGiFHA.2180@TK2MSFTNGP15.phx.gbl...
    > Thanks Luke,
    >
    > Yes, the web service is set to use Integrated authentication and anonymous
    > access is disabled.
    >
    > My code was passing credientials like you illustrated. The link you
    > attached guided me to another kb article which solved my problem.
    >
    > [url]http://support.microsoft.com/kb/811318/EN-US/[/url]
    >
    > I changed my code to use the CredentialCache class and it worked like
    > this:
    > localhost.Service ws = new localhost.Service();
    >
    > System.Net.CredentialCache cache = new System.Net.CredentialCache();
    > cache.Add( new Uri(ws.Url), "Negotiate", new
    > System.Net.NetworkCredential("userName", "password", "domain"));
    > ws.Credentials = cache;
    >
    > Response.Write(ws.HelloWorld());
    >
    > Thanks,
    >
    > Marshall
    >

    Marshall Guest

  6. #5

    Default Re: Trying to pass NetworkCredential to WebService

    Hi Marshall,

    When your webservice's virtual dir requires Authentication(disabled
    anomymous), the clientside need to provide a certain credential for
    authentication. For your scenario, that's the ASP.NET webapp. So in your
    ASP.NET's webservice calling code, we need to attach a NetworkCredential to
    the webservice proxy instance.

    As for the further problem you mentioned,
    ==================
    So this still is a problem because my web service needs to run in
    its own pool because I tie Sql Server permissions to its identity.
    ===================

    would you provide some further description on this? Based on my
    understanding, your ASP.NET webservice can surely to running in its own
    application pool (with its own identity) different from the ASP.NET
    webapp's.

    Looking forward to your response.

    Thanks,

    Steven Cheng
    Microsoft Online Support

    Get Secure! [url]www.microsoft.com/security[/url]
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
    --------------------
    | From: "Marshall" <marshall@newsgroup.nospam>
    | References: <OqRQFA9hFHA.2904@tk2msftngp13.phx.gbl>
    <JUjsKACiFHA.2800@TK2MSFTNGXA01.phx.gbl>
    <#GmyXSGiFHA.2180@TK2MSFTNGP15.phx.gbl>
    | Subject: Re: Trying to pass NetworkCredential to WebService
    | Date: Thu, 14 Jul 2005 07:52:46 -0400
    | Lines: 34
    | X-Priority: 3
    | X-MSMail-Priority: Normal
    | X-Newsreader: Microsoft Outlook Express 6.00.3790.1830
    | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.1830
    | X-RFC2646: Format=Flowed; Response
    | Message-ID: <u7BlPqGiFHA.4000@TK2MSFTNGP12.phx.gbl>
    | Newsgroups: microsoft.public.dotnet.framework.aspnet.webservic es
    | NNTP-Posting-Host: 66-195-172-195.gen.twtelecom.net 66.195.172.195
    | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP12.phx.gbl
    | Xref: TK2MSFTNGXA01.phx.gbl
    microsoft.public.dotnet.framework.aspnet.webservic es:7405
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webservic es
    |
    | Actually, my statement was incorrect. The problem was that my web
    service
    | was running in its own application pool with an identity of a domain
    | account. So this still is a problem because my web service needs to run
    in
    | its own pool because I tie Sql Server permissions to its identity.
    |
    | "Marshall" <marshall@newsgroup.nospam> wrote in message
    | news:%23GmyXSGiFHA.2180@TK2MSFTNGP15.phx.gbl...
    | > Thanks Luke,
    | >
    | > Yes, the web service is set to use Integrated authentication and
    anonymous
    | > access is disabled.
    | >
    | > My code was passing credientials like you illustrated. The link you
    | > attached guided me to another kb article which solved my problem.
    | >
    | > [url]http://support.microsoft.com/kb/811318/EN-US/[/url]
    | >
    | > I changed my code to use the CredentialCache class and it worked like
    | > this:
    | > localhost.Service ws = new localhost.Service();
    | >
    | > System.Net.CredentialCache cache = new System.Net.CredentialCache();
    | > cache.Add( new Uri(ws.Url), "Negotiate", new
    | > System.Net.NetworkCredential("userName", "password", "domain"));
    | > ws.Credentials = cache;
    | >
    | > Response.Write(ws.HelloWorld());
    | >
    | > Thanks,
    | >
    | > Marshall
    | >
    |
    |
    |

    Steven Cheng[MSFT] Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139