none
WCF에서 HTTP POST 사용하기 질문 RRS feed

  • 질문

  • MSDN 참고해서 WCF서버를 만들어 보고 있는데요 문제가 생기네요.
    간단히 설명드리면 요청은 HTTP GET, POST 두가지 지원하려고 하고 응답은 Json으로 받으려고 합니다.
    이때 POST 방식으로 요청을 처리하는 부분에서 오류가 나고 있네요.
    고수님들 도와주세요

    참고한 MSDN 링크
    http://msdn.microsoft.com/ko-kr/library/bb412178.aspx


    namespace MyServiceRestGetPost
    {
    	[ServiceContract]
    	public interface IMyMethod
    	{
    		[OperationContract]
    		[WebGet]
    		string EchoWithGet(string s);
    
    		[OperationContract]
    		[WebInvoke]
    		string EchoWithPost(string s);
    	}
    	
    	public class MyMethod : IMyMethod
    	{
    		#region IMyMethod Members
    
    		public string EchoWithGet(string s)
    		{
    			return s;
    		}
    
    		public string EchoWithPost(string s)
    		{
    			return s;
    		}
    
    		#endregion
    	}
    }
    





    Web.config 파일입니다.

      <system.serviceModel>
    		
    		<services>
    			<service name="MyServiceRestGetPost.MyMethod">
    				<endpoint
    					address=""
    					binding="webHttpBinding"
    					contract="MyServiceRestGetPost.IMyMethod"
    					behaviorConfiguration="webHttpBh"/>
    			</service>
    		</services>
    		
        <behaviors>
    
    	<endpointBehaviors>
    		<behavior name="webHttpBh">
    			<webHttp/>
    		</behavior>
    	</endpointBehaviors>
    
      </system.serviceModel>
    



    이렇게 구성해두고 실행해서 IIS를 돌렸고 GET 요청은 성공하는 것을 확인했는데 POST 요청은 500 에러가 나네요.
    아래는 fiddler 요청 응답 캡쳐입니다.

    POST 요청

    POST http://localhost:14062/MyMethod.svc/EchoWithPost HTTP/1.1
    Content-Type: application/json
    User-Agent: Fiddler
    Host: localhost:14062
    Content-Length: 5
    
    s=hhd
    

    POST 응답

    HTTP/1.1 400 Bad Request
    Cache-Control: private
    Content-Length: 1687
    Content-Type: text/html
    Server: Microsoft-IIS/8.0
    X-AspNet-Version: 4.0.30319
    X-SourceFiles: =?UTF-8?B?Qzpcc3ZuLXJvb3RccHJvamVjdFwxMjA5MjZfV2NmU3R1ZHlcTXlTZXJ2aWNlUmVzdEdldFBvc3RcTXlTZXJ2aWNlUmVzdEdldFBvc3RcTXlNZXRob2Quc3ZjXEVjaG9XaXRoUG9zdA==?=
    X-Powered-By: ASP.NET
    Date: Thu, 27 Sep 2012 09:07:16 GMT
    
    <?xml version="1.0" encoding="utf-8"?>
    <!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>요청 오류</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>
        <div id="content">
          <p class="heading1">요청 오류</p>
          <p>요청을 처리하는 동안 서버에서 오류가 발생했습니다. 자세한 내용은 서버 로그를 참조하십시오.</p>
        </div>
      </body>
    </html>    
    2012년 9월 27일 목요일 오전 9:24

답변