2
WebAPI 4.0에 기반한 서비스가 있지만 일부 클라이언트에서 XML 대신 JSON을 받는데 문제가 있습니다. 실제 서비스의 WebAPI 내부에서 어떤 일이 벌어지고 있는지 어떻게 볼 수 있습니까?WebAPI 응답 추적을 어떻게 활성화합니까?
WebAPI 4.0에 기반한 서비스가 있지만 일부 클라이언트에서 XML 대신 JSON을 받는데 문제가 있습니다. 실제 서비스의 WebAPI 내부에서 어떤 일이 벌어지고 있는지 어떻게 볼 수 있습니까?WebAPI 응답 추적을 어떻게 활성화합니까?
컴파일 및 배치 코드베이스가이 세트가 있는지 확인하십시오 : 로그 파일에이 물건을 볼 수
<configuration>
<system.diagnostics>
<trace autoflush="false" indentsize="4">
<listeners>
<add name="myListener"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="E:\CompressedLogs\Service1-WebApi-TraceOutput.log" />
<remove name="Default" />
</listeners>
</trace>
</system.diagnostics>
</configuration>
:
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// etc.
config.EnableSystemDiagnosticsTracing();
// etc.
}
}
이 그런 다음 Web.config
파일이 추가
w3wp.exe Information: 0 : Request, Method=GET, Url=http://MonkeyChops.potato.org/v1/PantsSpiderman/431?api_key=0, Message='http://MonkeyChops.potato.org/v1/PantsSpiderman/431?api_key=0'
w3wp.exe Information: 0 : Message='PantsSpiderman', Operation=DefaultHttpControllerSelector.SelectController
w3wp.exe Information: 0 : Message='Spandex.MonkeyChops.WebApi.Controllers.PantsSpidermanController', Operation=DefaultHttpControllerActivator.Create
w3wp.exe Information: 0 : Message='Spandex.MonkeyChops.WebApi.Controllers.PantsSpidermanController', Operation=HttpControllerDescriptor.CreateController
w3wp.exe Information: 0 : Message='Selected action 'Get(String id)'', Operation=ApiControllerActionSelector.SelectAction
w3wp.exe Information: 0 : Message='Parameter 'id' bound to the value '431'', Operation=ModelBinderParameterBinding.ExecuteBindingAsync
w3wp.exe Information: 0 : Message='Model state is valid. Values: id=431', Operation=HttpActionBinding.ExecuteBindingAsync
w3wp.exe Information: 0 : Message='Will use same 'XmlMediaTypeFormatter' formatter', Operation=XmlMediaTypeFormatter.GetPerRequestFormatterInstance
w3wp.exe Information: 0 : Message='Selected formatter='XmlMediaTypeFormatter', content-type='text/xml; charset=utf-8'', Operation=DefaultContentNegotiator.Negotiate
w3wp.exe Information: 0 : Message='Action returned 'StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.ObjectContent`1[[Spandex.MonkeyChops.Models.Pants.result, Spandex.MonkeyChops.WebApi, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], Headers:
{
Cache-Control: public, must-revalidate, max-age=86400
Content-Type: text/xml; charset=utf-8
}'', Operation=ReflectedHttpActionDescriptor.ExecuteAsync
w3wp.exe Information: 0 : Operation=ApiControllerActionInvoker.InvokeActionAsync, Status=200 (OK)
w3wp.exe Information: 0 : Operation=PantsSpidermanController.ExecuteAsync, Status=200 (OK)
w3wp.exe Information: 0 : Response, Status=200 (OK), Method=GET, Url=http://MonkeyChops.potato.org/v1/PantsSpiderman/431?api_key=0, Message='Content-type='text/xml; charset=utf-8', content-length=unknown'
w3wp.exe Information: 0 : Operation=XmlMediaTypeFormatter.WriteToStreamAsync
w3wp.exe Information: 0 : Operation=PantsSpidermanController.Dispose
감사! 다음 NuGet 패키지에 대한 참조를 추가해야했습니다 :'Microsoft.AspNet.WebApi.Tracing' – ne1410s