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

안녕하세요.

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

이번에 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)
981김창욱7/11/201121199주식형태의 프로그램 처럼 SQL서버의 특정 필드 데이터의 변화가 있을때 재 클라이언트가 정보를 갱신 할 수 있게 하는 방법은 없을까요? [2]
980YJ7/7/201120928App Pool idle time 과 WCF 서비스의 비동기 function 호출. [3]
979왕초보7/1/201119223Apache + IIS Redirect [2]
9776/16/201123161웹컨트롤 어느거 쓰는게 좋나요 [1]
976박성준6/13/201118661VS2008 Add-in 구현 관련 질문 [4]
972김길6/6/201120937메모리 해제 예외 처리 관련.. [2]
971강동원5/29/201118481firebird install건 [1]
970임동찬5/18/201119264ASP.net 솔루션 디버깅 관련 [1]
969이성환5/4/201120904WMI 를 사용하지 않고 하드웨어 정보를 가져올 수 없을까요? [3]
968김동미4/28/201120339안녕하세요 다시 한번 문의를 드립니다.. [2]파일 다운로드1
967임동찬4/22/201123026C# using문 관련 [9]
964김동미4/18/201120668wcf IsOneWay 속성관련 문의 입니다..
965정성태4/18/201121977    답변글 [답변]: wcf IsOneWay 속성관련 문의 입니다..
966김동미4/19/201119590        답변글 [답변]: [답변]: wcf IsOneWay 속성관련 문의 입니다.. [1]
963최재훈4/12/201118235wcf inactivityTimeout 설정시 문의 사항이 있습니다. [2]
962임동찬4/8/201117879TFS 사용관련 [1]
961임동찬4/7/201118168XSD & XML & XmlCodeGenerator [2]
960임동찬4/5/201119857XML Schema Editor [4]
959immm3/24/201117600로그인 연동 어려운 건가요? [1]
958꼭지3/3/201119757Supporting compressed request in WCF 3.5 [5]
957임동찬2/21/201120199WCF channel faulted 관련 [2]
956윤용한2/18/201123659WaitHandle.WaitOne 과 Stopwatch에 관한 질문 [3]
955최광욱2/17/201120341TFS 에서 소스 영구 제거 방법 [1]
954한장우2/16/201117999atl activeX 질문이요~ [1]
952박용운2/16/201118850IE8.0에서 BHO [1]
953박용운2/16/201118817    답변글 [답변]: IE8.0에서 BHO
... 61  62  63  64  [65]  66  67  68  69  70  71  72  73  74  75  ...