Microsoft MVP성태의 닷넷 이야기
WCF RESTful Service에서 enum을 parameter로 쓰는방법 [링크 복사], [링크+제목 복사],
조회: 15355
글쓴 사람
개태
홈페이지
첨부 파일
 

안녕하세요.

성태님에게 얻은 정보로 많은 도움을 받고 있습니다.^^

이번에 1개의 Service 함수로 OperationContract와 RESTful API를 같이 구현하고자 합니다.
문제는, Parameter로 enum타입을 받을시 OperationContract는 별 문제가 없지만..
RESTful API의 UriTemplate에 맵핑시는 에러가 나더군요..ㅠㅠ

굳이 해결하자면 RESTful API용 Service함수를 따로 만들어서, string 또는 int로 값을받아서 enum으로 변환 하면되지만,
이번 목표는 하나의 Service함수로 Soap메시지 반환과 RESTful API 호출시 json 반환을 목표로 하고 있습니다.
혹시 해결방법 알 수 있을까요?

=======================================================================================================================================

아래는 에러 내용 입니다.

'/' 응용 프로그램에 서버 오류가 있습니다.
'ILeService' 계약의 'GetCode' 작업에 'string' 형식을 사용하지 않는 경로 변수 'type'이(가) 있습니다. UriTemplate 경로 세그먼트에 대한 변수에는 'string' 형식이 있어야 합니다.
설명: 현재 웹 요청을 실행하는 동안 처리되지 않은 예외가 발생했습니다. 스택 추적을 검토하여 발생한 오류 및 코드에서 오류가 발생한 위치에 대한 자세한 정보를 확인하십시오.

예외 정보: System.InvalidOperationException: 'ILeService' 계약의 'GetCode' 작업에 'string' 형식을 사용하지 않는 경로 변수 'type'이(가) 있습니다. UriTemplate 경로 세그먼트에 대한 변수에는 'string' 형식이 있어야 합니다.

소스 오류:
현재 웹 요청을 실행하는 동안 처리되지 않은 예외가 생성되었습니다. 아래의 예외 스택 추적을 사용하여 예외의 원인 및 위치 정보를 확인할 수 있습니다.

스택 추적:
[InvalidOperationException: 'ILeService' 계약의 'GetCode' 작업에 'string' 형식을 사용하지 않는 경로 변수 'type'이(가) 있습니다. UriTemplate 경로 세그먼트에 대한 변수에는 'string' 형식이 있어야 합니다.]
   System.ServiceModel.Dispatcher.UriTemplateClientFormatter.Populate(Dictionary`2& pathMapping, Dictionary`2& queryMapping, Int32& totalNumUTVars, UriTemplate& uriTemplate, OperationDescription operationDescription, QueryStringConverter qsc, String contractName) +778
   System.ServiceModel.Description.WebHttpBehavior.GetRequestDispatchFormatter(OperationDescription operationDescription, ServiceEndpoint endpoint) +236
   System.ServiceModel.Description.WebHttpBehavior.ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher) +1746
   System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription description, ServiceHostBase serviceHost) +3270
   System.ServiceModel.ServiceHostBase.InitializeRuntime() +65
   System.ServiceModel.ServiceHostBase.OnBeginOpen() +35
   System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout) +49
   System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +308
   System.ServiceModel.HostingManager.ActivateService(ServiceActivationInfo serviceActivationInfo, EventTraceActivity eventTraceActivity) +110
   System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath, EventTraceActivity eventTraceActivity) +641

[ServiceActivationException: 컴파일 중 발생한 예외로 인해 '/LeService.svc' 서비스를 활성화할 수 없습니다. 예외 메시지: 'ILeService' 계약의 'GetCode' 작업에 'string' 형식을 사용하지 않는 경로 변수 'type'이(가) 있습니다. UriTemplate 경로 세그먼트에 대한 변수에는 'string' 형식이 있어야 합니다..]
   System.Runtime.AsyncResult.End(IAsyncResult result) +500298
   System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +174
   System.ServiceModel.Activation.ServiceHttpModule.EndProcessRequest(IAsyncResult ar) +351498
   System.Web.AsyncEventExecutionStep.InvokeEndHandler(IAsyncResult ar) +156
   System.Web.AsyncEventExecutionStep.OnAsyncEventCompletion(IAsyncResult ar) +9900796

=======================================================================================================================================

아래는 구현 코드 입니다.

namespace Test.Service
{
    partial interface ILeService
    {
        [OperationContract]
        [WebInvoke(Method = "GET", UriTemplate = "code/{type}/{code}", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
        CodeMaster GetCode(CodeType type, string code);
    }

    partial class LeService : ILeService
    {
        public CodeMaster GetCode(CodeType type, string code)
        {
            var db = new CodeMasterRepository();

            return db.SelectCode(type, code);
        }
    }

    [DataContract]
    public enum CodeType
    {
        [EnumMember]
        Department = 0,

        [EnumMember]
        JobGrade = 1,

        [EnumMember]
        Role = 2,
    }
}








[최초 등록일: ]
[최종 수정일: 5/4/2019]


비밀번호

댓글 작성자
 



2019-05-04 04시48분
이건가요?

Passing Enum & Custom Classes to WCF RESTful service using UriTemplate
; https://stackoverflow.com/questions/31184719/passing-enum-custom-classes-to-wcf-restful-service-using-uritemplate
정성태
2019-05-04 11시42분
[개태] 벌서 답변 달아주셨네요.ㅎㅎ

올려주신 링크는 이미 확인했던 링크인데, 답변에 보면 enum은 QueryString에서 원래 정상작동 한다고 하더군요.
전 안되는데 말이죠..ㅠㅠ
[guest]

... 61  62  63  64  65  [66]  67  68  69  70  71  72  73  74  75  ...
NoWriterDateCnt.TitleFile(s)
950이성환2/9/201119383Windows application 프로젝트를 참조 했을 때 생성되는 실행파일을 직접 실행 불가능하도록 하고 싶습니다. [6]파일 다운로드1
947김순조1/24/201119005.NET based Com에서 Native ActiveX로 이벤트 보내기?? [2]파일 다운로드1
943김기룡1/3/201122060닷넷 에러시 조치사항관련... [2]
942김기룡12/27/201017070Thread 안정성 관련 문의 드립니다. [2]
941최광욱12/20/201016832정성태님 올리신 글중에 [1]
940최광욱12/20/201018603Assembly Unloading 관련해서 [2]
939최광욱12/20/201017232IIS 로그 읽기 [1]
938날쌘돌이12/14/201018010자바로 asp.net 인증하기 [3]
935김기룡12/13/201028357c#에서 c++로 개발된 dll에 byte[] 전달 관련하여 문의 드립니다. [6]
934임동찬12/7/201015844System.Reflection.Assembly.GetTypes() 메서드에 대해 [1]
929김준호12/2/201016039안녕하세요 비주얼베이직 2005 닷넷 관련 문의입니다 [1]
928김준호11/30/201016598안녕하세요 비주얼베이직 2005 닷넷 관련 문의입니다 [1]파일 다운로드1
927임동찬11/30/201017968Windows\\Temp 폴더의 이름모를 .tmp 파일들에 대해서 [1]
926이승규11/26/201037912IP접속 시도시 ORA-12504 에러 [1]
925임동찬11/11/201015506다른 프로그램의 컨트롤 건드려보기_추가질문(2) [1]
924임동찬11/10/201016285다른 프로그램의 컨트롤 건드려보기_추가질문 [1]
923임동찬11/9/201018758다른 프로그램의 컨트롤 건드려보기 [1]
922박태근11/2/201017431html5의 shape파일 관련 [1]파일 다운로드1
921박태근11/1/201018169DataTable 의 Binary변환! [1]
920김재영10/26/201018337GAC에 등록된 어셈블리를 Visual Studio에서 참조 대화상자에 보이게 할려면 어떤 방법이 있습니까? [2]
919임동찬10/22/201016782IStream [1]
918임동찬10/21/201016001System.Runtime.InteropServices.ComTypes.IStream 관련 [1]
917한귀순10/20/201020230IIS 최초 loading 시 속도 [2]
916임동찬10/15/201016431file lock 관련 [2]
915오병태10/11/201015219바쁘신대 답변 감사드립니다. [1]
914오병태10/11/201015422감사드립니다. 염치없지만 또 한번 문의드립니다. [2]
... 61  62  63  64  65  [66]  67  68  69  70  71  72  73  74  75  ...