0

I am having some troubles with an asp.net WebApi project. I am using the rtm bits.

Within my api controller I have this

[HttpPut]
public Business Update([FromBody]Business business)
{
    try
    {
        if (business.Id == Guid.Empty)
        {
            throw new HttpResponseException(HttpStatusCode.BadRequest);
        }

        return _repository.Update(business);

    }
    catch (Exception ex)
    {
        log4net.ILog log = log4net.LogManager.GetLogger(this.GetType());
        log.Info(string.Format("Update Error Business"));
        log.Info(ex);
        throw;
    }
}

My mvc4 application I am calling this api method from a repository within my application

public static HttpResponseMessage Put(string apiMethod,string baseAddress,object objectData)
{
    var myHttpClient = new HttpClient
    {
        BaseAddress = new Uri(baseAddress)
    };
    myHttpClient.DefaultRequestHeaders.Authorization = new BasicAuthenticationHeaderValue("username", "Password1");
    myHttpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
    var put = myHttpClient.PutAsJsonAsync(apiMethod, objectData);
    var x = put.Result;
    return x;
}

I keep getting a server 500 error. I have a breakpoint on the api controller and its not getting hit. If a manually call the api from a 3rd party tool the api is called.

I have checked all of the basic things but can't seem to figure out whats going on.

Anyone got any tips I can use to figure out whats going wrong?

Antony Scott
  • 21,690
  • 12
  • 62
  • 94
Diver Dan
  • 9,953
  • 22
  • 95
  • 166
  • Have you set `GlobalConfiguration.Configuration.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;` to see the real error? – Claudio Redi Aug 29 '12 at 21:13
  • Just added it and nothing appears to have changed – Diver Dan Aug 29 '12 at 21:28
  • Is this a WebHost/SelfHost scenario?...if its SelfHost, exceptions during formatter writes would be not be having details and would just be 500 internal server error...regarding "I have a breakpoint on the api controller and its not getting hit. If a manually call the api from a 3rd party tool the api is called.", could share your routes and the url that you are sending? – Kiran Aug 29 '12 at 22:41
  • Its a webhosted application. Within the same solution just a separate project. I think the route is fine as I am able to call it from other methods – Diver Dan Aug 29 '12 at 23:47
  • Did you check how the sent request looks like from Fiddler...probably you can get some new insights... – Kiran Aug 30 '12 at 00:45
  • Take a look at this answer from Kiran, http://stackoverflow.com/a/11004784/471565 it should help you get the actual error details if theres an exception being thrown during a formatter write depending on what version you are running. – gdp Aug 30 '12 at 06:16

1 Answers1

0

I am too stuck on a similar scenario. Not sure if it is exactly the case as yours. Generally PUT/DELETE has some issues. Here is my issue (you can decide if it resembles yours): PUT and DELETE returns 404 for asp.net webapi in Windows 2008 Server IIS 7 and 7.5

Community
  • 1
  • 1
Sando
  • 667
  • 1
  • 6
  • 14