JSON 대신 XML을 반환하도록 웹 API 컨트롤러 내에서 작업을 구성하는 방법은 무엇입니까?웹 API 액션에서 JSON 대신 XML을 반환하는 방법?
[HttpGet]
public UserProfile SearchByEmail(string siteName, string email)
{
var userProfile = this._profileFinderByEmail.Find(siteName, email);
if (userProfile == null)
{
throw new HttpResponseException(HttpStatusCode.NotFound);
}
return userProfile;
}
나는이 작업을 실행할 때, 그것은 XML이 아닌 응용 프로그램/JSON을 반환
나는 XMLELEMENT 속성을 가지고있는 사용자 프로필 개체를 반환하는 작업을해야합니다. 어떻게하면 XML을 반환 할 수 있습니까? 피들러에 의해 나는 아래의 수락 헤더 키를 가지고 전송 된 요청 헤더를 판단
: 나는 XML을 반환하기를 기대하지만, 그렇지 않은
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
.
문제를 해결하는 방법은 무엇입니까? ,
Status Code:406 Not Acceptable
컨트롤러를 'ApiController'에 연결 했습니까? – Sandy
예 내 컨트롤러가 ApiController에서 상속됩니다. 덕분에 –