2011-03-22 3 views
2

나는 고객을 추가해야하는 방법이있다 :WCF. REST 아키텍처. JSON (POST)에서 클라이언트의 객체를 얻는 방법

 [WebInvoke(UriTemplate = "/", Method = "POST", ResponseFormat = WebMessageFormat.Json)] 
    [OperationContract] 
    string CreateCustomer(Customer customer); 

그리고이 방법에 대한 모든 호출이 실패하기 때문에 나는 문제가있다! GET이 제대로 작동하는 것과 같은 방법입니다 (url의 Customer object bu request id 만 반환하면됩니다). 응답 wcf 서비스에서 :

Status: 400 

headers = { 
     "Cache-Control" = private; 
     "Content-Length" = 2900; 
     "Content-Type" = "text/html"; 
     Date = "Tue, 22 Mar 2011 12:51:09 GMT"; 
     Server = "Microsoft-IIS/7.0"; 
     "X-Aspnet-Version" = "4.0.30319"; 
     "X-Powered-By" = "ASP.NET"; 
    } 


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
    <title>Request Error</title> 
    <style>BODY { color: #000000; background-color: white; font-family: Verdana; margin-left: 0px; margin-top: 0px; } #content { margin-left: 30px; font-size: .70em; padding-bottom: 2em; } A:link { color: #336699; font-weight: bold; text-decoration: underline; } A:visited { color: #6699cc; font-weight: bold; text-decoration: underline; } A:active { color: #336699; font-weight: bold; text-decoration: underline; } .heading1 { background-color: #003366; border-bottom: #336699 6px solid; color: #ffffff; font-family: Tahoma; font-size: 26px; font-weight: normal;margin: 0em 0em 10px -20px; padding-bottom: 8px; padding-left: 30px;padding-top: 16px;} pre { font-size:small; background-color: #e5e5cc; padding: 5px; font-family: Courier New; margin-top: 0px; border: 1px #f0f0e0 solid; white-space: pre-wrap; white-space: -pre-wrap; word-wrap: break-word; } table { border-collapse: collapse; border-spacing: 0px; font-family: Verdana;} table th { border-right: 2px white solid; border-bottom: 2px white solid; font-weight: bold; background-color: #cecf9c;} table td { border-right: 2px white solid; border-bottom: 2px white solid; background-color: #e5e5cc;}</style> 
    </head> 
    <body> 

및 문제가 메서드에서 단계 전에 점유하기 때문에 나는 메서드를 디버깅 할 수 없습니다.

내 첫 번째 인수 문제가 고객 고객 POST 어떻게 할 권리? 그리고 그것으로 작업하는 방법 (서버의 Parse json)?

피들러

enter image description here

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd"> 
<HTML><HEAD><TITLE>Bad Request</TITLE> 
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD> 
<BODY><h2>Bad Request - Invalid Header</h2> 
<hr><p>HTTP Error 400. The request has an invalid header name.</p> 
</BODY></HTML> 

하지만 고객과 같은 문제인지 잘 모르겠습니다.

+2

WCF REST 서비스를위한 PoC를 개발할 때 클라이언트와 서버간에 전송되는 것을 볼 수있는 Fiddler라는 도구가 있습니다. 매우 유용했습니다. http : //www.fiddler2.com/fiddler2/ –

+1

나는 그것을 사용한다. 그리고 뭐가 잘못 됐는지 알 수가 없어! – Evgeny

답변

2

나는 당신이 얻는 무슨 문제가 완전히 모르겠지만,이로 보았을 때, 나는 다른 머리글했다 :에서 몸을 다진 것으로

또한 Content-Type = application/xml

, 당신은 표시를하여 질문, 유용 할 수 있습니다.

1

고객 요청의 내용 유형이 유효하지 않습니다. application/json

관련 문제