| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using CoreWCF.Channels; |
| | | 6 | | using CoreWCF.Description; |
| | | 7 | | using CoreWCF.Dispatcher; |
| | | 8 | | |
| | | 9 | | namespace CoreWCF.Web |
| | | 10 | | { |
| | | 11 | | [AttributeUsage(AttributeTargets.Method)] |
| | | 12 | | public sealed class WebInvokeAttribute : Attribute, IOperationContractAttributeProvider, IOperationBehavior |
| | | 13 | | { |
| | | 14 | | private WebMessageBodyStyle _bodyStyle; |
| | | 15 | | private WebMessageFormat _requestMessageFormat; |
| | | 16 | | private WebMessageFormat _responseMessageFormat; |
| | | 17 | | |
| | 244 | 18 | | public WebInvokeAttribute() |
| | | 19 | | { |
| | 244 | 20 | | } |
| | | 21 | | |
| | | 22 | | public WebMessageBodyStyle BodyStyle |
| | | 23 | | { |
| | 97 | 24 | | get { return _bodyStyle; } |
| | | 25 | | set |
| | | 26 | | { |
| | 200 | 27 | | if (!WebMessageBodyStyleHelper.IsDefined(value)) |
| | | 28 | | { |
| | 0 | 29 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val |
| | | 30 | | } |
| | | 31 | | |
| | 200 | 32 | | _bodyStyle = value; |
| | 200 | 33 | | IsBodyStyleSetExplicitly = true; |
| | 200 | 34 | | } |
| | | 35 | | } |
| | | 36 | | |
| | 297 | 37 | | public bool IsBodyStyleSetExplicitly { get; private set; } |
| | | 38 | | |
| | 136 | 39 | | public bool IsRequestFormatSetExplicitly { get; private set; } |
| | | 40 | | |
| | 223 | 41 | | public bool IsResponseFormatSetExplicitly { get; private set; } |
| | | 42 | | |
| | 291 | 43 | | public string Method { get; set; } |
| | | 44 | | |
| | | 45 | | public WebMessageFormat RequestFormat |
| | | 46 | | { |
| | | 47 | | get |
| | | 48 | | { |
| | | 49 | | |
| | 22 | 50 | | return _requestMessageFormat; |
| | | 51 | | } |
| | | 52 | | set |
| | | 53 | | { |
| | 114 | 54 | | if (!WebMessageFormatHelper.IsDefined(value)) |
| | | 55 | | { |
| | 0 | 56 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val |
| | | 57 | | } |
| | | 58 | | |
| | 114 | 59 | | _requestMessageFormat = value; |
| | 114 | 60 | | IsRequestFormatSetExplicitly = true; |
| | 114 | 61 | | } |
| | | 62 | | } |
| | | 63 | | |
| | | 64 | | public WebMessageFormat ResponseFormat |
| | | 65 | | { |
| | | 66 | | get |
| | | 67 | | { |
| | | 68 | | |
| | 44 | 69 | | return _responseMessageFormat; |
| | | 70 | | } |
| | | 71 | | set |
| | | 72 | | { |
| | 176 | 73 | | if (!WebMessageFormatHelper.IsDefined(value)) |
| | | 74 | | { |
| | 0 | 75 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val |
| | | 76 | | } |
| | | 77 | | |
| | 176 | 78 | | _responseMessageFormat = value; |
| | 176 | 79 | | IsResponseFormatSetExplicitly = true; |
| | 176 | 80 | | } |
| | | 81 | | } |
| | | 82 | | |
| | 341 | 83 | | public string UriTemplate { get; set; } |
| | | 84 | | |
| | | 85 | | void IOperationBehavior.AddBindingParameters(OperationDescription operationDescription, BindingParameterCollecti |
| | | 86 | | { |
| | 25 | 87 | | } // do nothing |
| | | 88 | | |
| | | 89 | | void IOperationBehavior.ApplyClientBehavior(OperationDescription operationDescription, ClientOperation clientOpe |
| | | 90 | | { |
| | 0 | 91 | | } // do nothing |
| | | 92 | | |
| | | 93 | | void IOperationBehavior.ApplyDispatchBehavior(OperationDescription operationDescription, DispatchOperation dispa |
| | | 94 | | { |
| | 25 | 95 | | } // do nothing |
| | | 96 | | |
| | | 97 | | void IOperationBehavior.Validate(OperationDescription operationDescription) |
| | | 98 | | { |
| | 25 | 99 | | } // do nothing |
| | | 100 | | |
| | | 101 | | internal WebMessageBodyStyle GetBodyStyleOrDefault(WebMessageBodyStyle defaultStyle) |
| | | 102 | | { |
| | 97 | 103 | | if (IsBodyStyleSetExplicitly) |
| | | 104 | | { |
| | 97 | 105 | | return BodyStyle; |
| | | 106 | | } |
| | | 107 | | else |
| | | 108 | | { |
| | 0 | 109 | | return defaultStyle; |
| | | 110 | | } |
| | | 111 | | } |
| | | 112 | | |
| | 25 | 113 | | OperationContractAttribute IOperationContractAttributeProvider.GetOperationContractAttribute() => new OperationC |
| | | 114 | | } |
| | | 115 | | } |