0
  1. I have webapi and method:

    public class ArticlesController : ApiController
    {
         //
         // GET: api/values
         public IEnumerable<Article> Get()
         {
             using (CollectionsEntities entities = new CollectionsEntities())
             {
                  return entities.Articles.ToList<Article>();
             }
         }
     }
    

It works fine, and check it in browser:

webapi works

  1. I create a client:

    public static class CollectionClient
    {
        private static readonly HttpClient client;
    
        public static Uri ServerBaseUri
        {
            get { return new Uri("http://localhost:10779/api/"); }
        }
    
        public static Boolean IsDirty { get; private set; }
    
        static CollectionClient()
        {
            IsDirty = true;
            client = new HttpClient(new DemoHttpMessageHandler());
        }
    
        // get all articles
        public static async Task<List<Article>> GetAllArticlesAsync()
        {
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            Uri serverUril = new Uri(ServerBaseUri, "Articles");            
            var response = await client.GetAsync(serverUril);
    
            response.EnsureSuccessStatusCode();
    
            var articles = await response.Content.ReadAsAsync<List<Article>>();
            IsDirty = false;
            return articles;   
        }
    }
    

The response gets 404 status code: enter image description here

ID_CAP_NETWORKING is checked to make sure it can access internet. Could anybody give me a hand? Thanks in advance!

2
  • Why do you have a windows-phone-7 tag on your post? Commented Dec 21, 2013 at 2:00
  • coz I access this web api from a program in windows phone 8 emulator Commented Dec 21, 2013 at 2:30

2 Answers 2

1

I only have experience with Android but "localhost" for the emulator is probably different than the "localhost" for your PC. Try using the internal subnet IP instead.

Sign up to request clarification or add additional context in comments.

4 Comments

i use 127.0.0.1 instead, still the same, any ideas?
127.0.0.1 is the same thing as the localhost (a loopback address). You need to use something like 192.168.1.x or whatever the local subnet is.
Here is a very similar question: stackoverflow.com/questions/13149304/… that has a detailed answer.
i use a public api to try, it works. that proves program is collect, will publish the web api and re-try. thnx.
0

In windows phone 7.x, the emulator shared the networking of the Host PC, that means: we could host services on our PC and access them from our code using htt://localhost..

In windows phone 8, the emulator is a virtual machine running under Hyper V, that means: you cannot access services on your PC using htt://localhost..

you must use the correct host name or raw IP address of our host PC in URIs

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.