locked
Client Authentication Web API RRS feed

  • Question

  • Im hoping someone can offer advice here for a problem thats taken several days trying to resolve.
    Im hoping to consume a service available here : Web API
    We are stuck with using either VS 2003 or VS 2005 (current company policy till next year review).
    I have to alter an existing WinForms application which pulls in a huge range of data from various and sundry external sites, be they remote FTP sites or web sites.
    The application currently accesses data from the particular web site via a web request and we are able to authenticate no problem. The data source is to change in the near future and we will have to consume the web service (above)
    However, I am having an amazing amount of trouble trying to authenticate.
    The app is written in C# and we dont want users to have to log in via a form. It should pass through the currently logged in user's credentials.
    I know this question has been asked thousands of times on the net ... Ive probably read half of the them during the last 3 or 4 days! But I havent been able to find a straight answer anywhere.
    How can we authenticate on to a web service from behind a proxy without asking the user to type credentials into forms. All answers will be gratefully received and trialled!! Its really driving me mad.
    As a side issue: why is it I can pass credentials through using CredentialCache.DefaultCredentials when calling a web request but cant when trying to access the API.
    Ill be one grateful lass if someone can help
    Kate


    Tuesday, December 2, 2008 10:24 PM

Answers

  • My guess is that the WebRequest route passes the credentials along in the manner that Internet Explorer does when viewing a website.  And that an actual WebService call is implemented in a different manner.

    As to getting the users credentials, I am not sure if there is an easy way to get their current password from windows.
    Mitchel Sellers, MCITP, MCPD, MCTS - http://www.mitchelsellers.com
    Wednesday, December 3, 2008 7:24 PM

All replies

  • My guess is that the WebRequest route passes the credentials along in the manner that Internet Explorer does when viewing a website.  And that an actual WebService call is implemented in a different manner.

    As to getting the users credentials, I am not sure if there is an easy way to get their current password from windows.
    Mitchel Sellers, MCITP, MCPD, MCTS - http://www.mitchelsellers.com
    Wednesday, December 3, 2008 7:24 PM
  •  Thank you for the reply Mitchel its much appreciated.

    Ive now had some success with this and as the question is asked so many times on various internet forums I thought it might be useful to post my solution.

    Here is a code fragment including comments which should be self explanatory.

    For any new comers this is not production code!!! its just a little fragment Ive put on a click event to authenticate through the proxy server. Hope it helps someone:

    {      

                // just some values to use as test parameters

                DateTime dateFrom = new DateTime(2007,11,18,5,0,0);           

                DateTime dateTo = new DateTime(2007,11,20,5,0,0);

                string strName = "SAP, Actual Day";

                string strBuy = "SMP Buy, Actual Day";

                string strSell = "SMP Sell, Actual Day";

                string[] name = new string[]{strName,strBuy,strSell};
              

                // build request object to pass to web method

                CLSRequestObject oReq = new CLSRequestObject();

                  oReq.FromDate = dateFrom;          

                  oReq.ToDate = dateTo;

                  oReq.ApplicableForFlag = "N";

                  oReq.DateType = "gasday";

                  oReq.LatestFlag = "N";

                  oReq.PublicationObjectNameList = name;                  

                 // proxy uri
                 // substitute ip address with network address          

                Uri proxyUri = new Uri("http://xxx.xx.x.xx:8080/");

                PublicWebService clientP = new PublicWebService();

                clientP.Proxy = new WebProxy(proxyUri);

                clientP.Proxy.Credentials = CredentialCache.DefaultCredentials;

                clientP.UseDefaultCredentials = true;

               // Application.DoEvents();

                clientP.GetPublicationDataWM(oReq);           

            }



     

     

    Thursday, December 4, 2008 8:40 PM