Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I've created a WCF Restful service to get the data from the SQL server 2008 and hosted the service in IIS sever.When I access the service hosted in the IIS its working fine get the result from the database and display the result in browser in XML format. The problem is when I use the service in the another ASP.Net web application as service reference I cannot access the method in the service. I've checked in the web config file and made changes in bindings,contracts,address but after made changes it shows the error that "
The remote server returned an error: (404) Not Found.
"

What I have tried:

Made changes in the configuration file for the bindings and other things
Posted
Updated 12-May-16 1:34am

1 solution

C#
using (var client = new HttpClient())
{
    client.BaseAddress = new Uri("http://localhost:9000/");
    client.DefaultRequestHeaders.Accept.Clear();
    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

    // New code:
    HttpResponseMessage response = await client.GetAsync("api/products/1");
    if (response.IsSuccessStatusCode)
    {
        Product product = await response.Content.ReadAsAsync>Product>();
        Console.WriteLine("{0}\t${1}\t{2}", product.Name, product.Price, product.Category);
    }
}



for more details refer Calling a Web API From a .NET Client in ASP.NET Web API 2 (C#) | The ASP.NET Site
 
Share this answer
 
v2
Comments
Gowtham E 13-May-16 1:59am    
Thanks a lot Knuwar for taking time to comment for My question I've tried your code model and its working correctly. Once again thanks for your job.

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