Home Ping does not work in webApi
Reply: 0

Ping does not work in webApi

user1274 Published in July 16, 2018, 6:41 am

I have created a ping method in both a console application and webapi application. Ping works the console app but not the webapi app. It always is timedout. Here is the code I am using:

namespace Ping.Controllers
    public class PingController : Controller
        // GET api/values
        public async Task<IEnumerable<Models.PingItem>> Post([FromBody]List<string> hosts)
            List<Task<Models.PingItem>> tasks = new List<Task<Models.PingItem>>();

            foreach (var host in hosts)

            var results = await Task.WhenAll(tasks.ToArray());

            return results;

        private async Task<Models.PingItem> Ping(string host)
            Models.PingItem pi = new Models.PingItem();
            Ping pingSender = new Ping();
            var result = await pingSender.SendPingAsync(host, 50000);
            pi.Host = host;
            pi.Live = result.Status == IPStatus.Success ? true : false;
            pi.Time = result.RoundtripTime;
            return pi;

Any ideas?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.315588 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO