Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
For Example,

i have a WCF service as:
http://team.abc.net/site/DSP/Training/_bin/LinkData.svc

from this service i have to get the data. i used the following code, but its throwing error as 'unauthorized'.

Also im not sure how to pass the username and password with the uri object, i tried with uri builder class also. but same problem.

Please do the needful.

What I have tried:

1st i added the service reference in solution as 'TrainingLinkService'.
var uri = new Uri("http://team.abc.net/site/DSP/Training/_bin/LinkData.svc");
TrainingLinkService.TrainingProgramReviewDataContext client = new TrainingLinkService.TrainingProgramReviewDataContext(uri);
var temp = from item in container.Documentation
            select item;
Posted
Updated 26-Sep-16 21:00pm
v6
Comments
Have you tried with the below...

<authentication mode="None" />

1 solution

Here is the solution: it was in Atom format, so i was bit confused to parse it.

C#
static List<DocumentationEntity> ParseAtom(string url, string username, string password)
        {
            try
            {
                var _xDocument = new XDocument();
                var _Request = WebRequest.Create(url) as HttpWebRequest;
                    _Request.Method = "GET";
                    _Request.Credentials = new NetworkCredential(username, password);
                    
                using (HttpWebResponse response = _Request.GetResponse() as HttpWebResponse)
                {
                    using (Stream stream = response.GetResponseStream())
                    {
                        _xDocument = XDocument.Load(stream);
                    }
                }

                var entries = from root in _xDocument.Root.Elements().Where(i => i.Name.LocalName == "entry")
                              from entry in root.Elements().Where(i => i.Name.LocalName == "properties")
                              select new DocumentationEntity
                              {
                                  ContentTypeID = entry.Elements().First(i => i.Name.LocalName == "ContentTypeID").Value,
                                  Name = entry.Elements().First(i => i.Name.LocalName == "Name").Value,
                                  Description = entry.Elements().First(i => i.Name.LocalName == "Description").Value,
                                  PictureWidth = entry.Elements().First(i => i.Name.LocalName == "PictureWidth").Value,
                                  StageValue = entry.Elements().First(i => i.Name.LocalName == "StageValue").Value,
                                  ScriptReview = entry.Elements().First(i => i.Name.LocalName == "ScriptReview").Value,
                                  ScriptReview0 = entry.Elements().First(i => i.Name.LocalName == "ScriptReview0").Value,
                                  ScriptCompleted = entry.Elements().First(i => i.Name.LocalName == "ScriptCompleted").Value,
                                  Id = entry.Elements().First(i => i.Name.LocalName == "Id").Value,
                                  ContentType = entry.Elements().First(i => i.Name.LocalName == "ContentType").Value,
                                  Created = entry.Elements().First(i => i.Name.LocalName == "Created").Value,
                                  CreatedById = entry.Elements().First(i => i.Name.LocalName == "CreatedById").Value,
                                  Modified = entry.Elements().First(i => i.Name.LocalName == "Modified").Value,
                                  ModifiedById = entry.Elements().First(i => i.Name.LocalName == "ModifiedById").Value,
                                  CopySource = entry.Elements().First(i => i.Name.LocalName == "CopySource").Value,
                                  ApprovalStatus = entry.Elements().First(i => i.Name.LocalName == "ApprovalStatus").Value,
                                  Path = entry.Elements().First(i => i.Name.LocalName == "Path").Value,
                                  CheckedOutToId = entry.Elements().First(i => i.Name.LocalName == "CheckedOutToId").Value,
                                  VirusStatus = entry.Elements().First(i => i.Name.LocalName == "VirusStatus").Value,
                                  IsCurrentVersion = entry.Elements().First(i => i.Name.LocalName == "IsCurrentVersion").Value,
                                  Owshiddenversion = entry.Elements().First(i => i.Name.LocalName == "Owshiddenversion").Value,
                                  Version = entry.Elements().First(i => i.Name.LocalName == "Version").Value
                              };
                return entries.ToList();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                throw ex;
            }
        }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900