locked
Simple question to consume a single result from a service operation RRS feed

  • Question

  • I have a dataservice exposing a service operation:


        [WebGet]
        public PersonDetailsView GetByUserName(string networkUser)
        {
            if (string.IsNullOrEmpty(networkUser))
                throw new DataServiceException(400, "A networkUser must be supplied");

            return Person.GetPerson(networkUser);
        }


    How do I consume this from a client?

    I can build the uri ->

    Uri uri = new Uri(AppSettings.Instance["PersonDataServiceUrl"].ToString());
    var proxy = new PersonService.PersonDataContext(uri);

    Uri serviceUri = new Uri(uri.AbsoluteUri + "/GetByUserName?networkUser='" + UserName + "'");

    I can't use:

     proxy.Execute<PersonService.PersonDetailsView>(serviceUrl);


    As I am expecting a single result not a enumerable result?
    Sunday, October 12, 2008 10:16 PM

Answers

  • Use First().  Something like:

     

    var person = proxy.Execute<Person>(uri).First();

    Monday, October 13, 2008 5:45 AM