asp.net mvc 4 - Internal Server Error 500 in Web APi MVC4 -


i called httppost method controller web api. other methods, response ok , method works except below mentioned method stating error

{statuscode: 500, reasonphrase: 'internal server error', version: 1.1, content: system.net.http.streamcontent, headers: {   pragma: no-cache   connection: close   cache-control: no-cache   date: fri, 16 aug 2013 09:49:25 gmt   server: asp.net   server: development   server: server/10.0.0.0   x-aspnet-version: 4.0.30319   content-length: 1855   content-type: application/json; charset=utf-8   expires: -1 }} 

my method

public int customerregistration(customerrequestresponse req)       {                 try                 {                     httpclient client = new httpclient();                     client.baseaddress = new uri(configurationmanager.appsettings["serveraddress"].tostring());                     client.defaultrequestheaders.accept.add(                     new mediatypewithqualityheadervalue("application/json"));                     uri gizmouri = null;                     var response = client.postasjsonasync("api/myaccount/customerregistration", req).result;                     int result = 0;                     if (response.issuccessstatuscode)                     {                         gizmouri = response.headers.location;                         result = response.content.readasasync<int32>().result;                     }                     return result;                 }                 catch { throw; }             } 

how identify mistake in code. suggestions ??

edit :: traced error specifying "system.net.http.objectcontent"

{method: post, requesturi: 'http://localhost:56003/api/myaccount/customerregistration', version: 1.1, content: system.net.http.objectcontent`1[[serviceentities.myaccount.customerrequestresponse, serviceentities, version=1.0.0.0, culture=neutral, publickeytoken=null]], headers: {   accept: application/json   content-type: application/json; charset=utf-8   content-length: 495 }} 

any suggestions fixing .?

edit1 :

</message><exceptionmessage>no mediatypeformatter available read object of type 'customerrequestresponse' content media type 'text/plain'.</exceptionmessage> 

the first thing verify request client doing correct - correct url, headers, body. in order can enable fiddler proxy in application. add section web.config , try running code again fiddler open - should able see request in fiddler:

<system.net>   <defaultproxy>     <proxy  proxyaddress="http://127.0.0.1:8888" />         </defaultproxy> </system.net> 

if request ok, check server trying connect , running , it's giving correct response correct headers.

i suspect should enough identify problem.

btw: in real life catch block useful actually? make more useful add log4net logging identify future issues.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -