2014年1月7日火曜日

.NETでJSONサービスを作って見た。インタフェースを間違えると↓のエラーが発生する。

.NETでJSONサービスを作って見た。インタフェースを間違えると↓のエラーが発生する。

コード
[OperationContract]
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "getBeforeHandlingAll/{trainingType}")]
BeforeHandlingListResponse GetBeforeHandlingAll(string traningType);
⇒文字列が異なるとエラーになるようです。
エラーメッセージ
WebHost で要求の処理に失敗しました。
 送信者の情報: System.ServiceModel.ServiceHostingEnvironment+HostingManager/7185836
 例外: System.ServiceModel.ServiceActivationException: The service '/HOGE/HogehogeService' cannot be activated due to an exception during compilation.  The exception message is: Operation 'GetBeforeHandlingAll' in contract 'IHogeService' has a UriTemplate that expects a parameter named 'TRAININGTYPE', but there is no input parameter with that name on the operation.. ---> System.InvalidOperationException: Operation 'GetBeforeHandlingAll' in contract 'IHogeService' has a UriTemplate that expects a parameter named 'TRAININGTYPE', but there is no input parameter with that name on the operation.
   場所 System.ServiceModel.Dispatcher.UriTemplateClientFormatter.Populate(Dictionary`2& pathMapping, Dictionary`2& queryMapping, Int32& totalNumUTVars, UriTemplate& uriTemplate, OperationDescription operationDescription, QueryStringConverter qsc, String contractName)
   場所 System.ServiceModel.Dispatcher.UriTemplateDispatchFormatter..ctor(OperationDescription operationDescription, IDispatchMessageFormatter inner, QueryStringConverter qsc, String contractName, Uri baseAddress)
   場所 System.ServiceModel.Description.WebHttpBehavior.GetRequestDispatchFormatter(OperationDescription operationDescription, ServiceEndpoint endpoint)
   場所 System.ServiceModel.Description.WebHttpBehavior.ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
   場所 System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription description, ServiceHostBase serviceHost)
   場所 System.ServiceModel.ServiceHostBase.InitializeRuntime()
   場所 System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout)
   場所 System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   場所 System.ServiceModel.ServiceHostingEnvironment.HostingManager.ActivateService(String normalizedVirtualPath)
   場所 System.ServiceModel.ServiceHostingEnvironment.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath)
   --- 内部例外スタック トレースの終わり ---
   場所 System.ServiceModel.ServiceHostingEnvironment.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath)
   場所 System.ServiceModel.ServiceHostingEnvironment.EnsureServiceAvailableFast(String relativeVirtualPath)
 プロセス名: w3wp
 プロセス ID: 19252


コード
[OperationContract]
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "getBeforeHandlingAll/{trainingType}")]
BeforeHandlingListResponse GetBeforeHandlingAll(int trainingType);
⇒受け取った文字をint型には出来ないようです。
エラーメッセージ
 WebHost で要求の処理に失敗しました。
 送信者の情報: System.ServiceModel.ServiceHostingEnvironment+HostingManager/40607348
 例外: System.ServiceModel.ServiceActivationException: The service '/HOGE/HogeService' cannot be activated due to an exception during compilation.  The exception message is: Operation 'GetBeforeHandlingAll' in contract 'IHogeService' has a path variable named 'trainingType' which does not have type 'string'.  Variables for UriTemplate path segments must have type 'string'.. ---> System.InvalidOperationException: Operation 'GetBeforeHandlingAll' in contract 'IHogeService' has a path variable named 'trainingType' which does not have type 'string'.  Variables for UriTemplate path segments must have type 'string'.
   場所 System.ServiceModel.Dispatcher.UriTemplateClientFormatter.Populate(Dictionary`2& pathMapping, Dictionary`2& queryMapping, Int32& totalNumUTVars, UriTemplate& uriTemplate, OperationDescription operationDescription, QueryStringConverter qsc, String contractName)
   場所 System.ServiceModel.Dispatcher.UriTemplateDispatchFormatter..ctor(OperationDescription operationDescription, IDispatchMessageFormatter inner, QueryStringConverter qsc, String contractName, Uri baseAddress)
   場所 System.ServiceModel.Description.WebHttpBehavior.GetRequestDispatchFormatter(OperationDescription operationDescription, ServiceEndpoint endpoint)
   場所 System.ServiceModel.Description.WebHttpBehavior.ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
   場所 System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription description, ServiceHostBase serviceHost)
   場所 System.ServiceModel.ServiceHostBase.InitializeRuntime()
   場所 System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout)
   場所 System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   場所 System.ServiceModel.ServiceHostingEnvironment.HostingManager.ActivateService(String normalizedVirtualPath)
   場所 System.ServiceModel.ServiceHostingEnvironment.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath)
   --- 内部例外スタック トレースの終わり ---
   場所 System.ServiceModel.ServiceHostingEnvironment.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath)
   場所 System.ServiceModel.ServiceHostingEnvironment.EnsureServiceAvailableFast(String relativeVirtualPath)
 プロセス名: w3wp
 プロセス ID: 19252

0 件のコメント:

コメントを投稿