| | | 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 WebGetAttribute : Attribute, IOperationContractAttributeProvider, IOperationBehavior |
| | | 13 | | { |
| | | 14 | | private WebMessageBodyStyle _bodyStyle; |
| | | 15 | | private WebMessageFormat _requestMessageFormat; |
| | | 16 | | private WebMessageFormat _responseMessageFormat; |
| | | 17 | | |
| | 1144 | 18 | | public WebGetAttribute() |
| | | 19 | | { |
| | 1144 | 20 | | } |
| | | 21 | | |
| | | 22 | | public WebMessageBodyStyle BodyStyle |
| | | 23 | | { |
| | 344 | 24 | | get { return _bodyStyle; } |
| | | 25 | | set |
| | | 26 | | { |
| | 680 | 27 | | if (!WebMessageBodyStyleHelper.IsDefined(value)) |
| | | 28 | | { |
| | 0 | 29 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val |
| | | 30 | | } |
| | | 31 | | |
| | 680 | 32 | | _bodyStyle = value; |
| | 680 | 33 | | IsBodyStyleSetExplicitly = true; |
| | 680 | 34 | | } |
| | | 35 | | } |
| | | 36 | | |
| | 1232 | 37 | | public bool IsBodyStyleSetExplicitly { get; private set; } |
| | | 38 | | |
| | 48 | 39 | | public bool IsRequestFormatSetExplicitly { get; private set; } |
| | | 40 | | |
| | 846 | 41 | | public bool IsResponseFormatSetExplicitly { get; private set; } |
| | | 42 | | |
| | | 43 | | public WebMessageFormat RequestFormat |
| | | 44 | | { |
| | | 45 | | get |
| | | 46 | | { |
| | | 47 | | |
| | 24 | 48 | | return _requestMessageFormat; |
| | | 49 | | } |
| | | 50 | | set |
| | | 51 | | { |
| | 24 | 52 | | if (!WebMessageFormatHelper.IsDefined(value)) |
| | | 53 | | { |
| | 0 | 54 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val |
| | | 55 | | } |
| | | 56 | | |
| | 24 | 57 | | _requestMessageFormat = value; |
| | 24 | 58 | | IsRequestFormatSetExplicitly = true; |
| | 24 | 59 | | } |
| | | 60 | | } |
| | | 61 | | |
| | | 62 | | public WebMessageFormat ResponseFormat |
| | | 63 | | { |
| | | 64 | | get |
| | | 65 | | { |
| | | 66 | | |
| | 110 | 67 | | return _responseMessageFormat; |
| | | 68 | | } |
| | | 69 | | set |
| | | 70 | | { |
| | 684 | 71 | | if (!WebMessageFormatHelper.IsDefined(value)) |
| | | 72 | | { |
| | 0 | 73 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val |
| | | 74 | | } |
| | | 75 | | |
| | 684 | 76 | | _responseMessageFormat = value; |
| | 684 | 77 | | IsResponseFormatSetExplicitly = true; |
| | 684 | 78 | | } |
| | | 79 | | } |
| | | 80 | | |
| | 1622 | 81 | | public string UriTemplate { get; set; } |
| | | 82 | | |
| | | 83 | | void IOperationBehavior.AddBindingParameters(OperationDescription operationDescription, BindingParameterCollecti |
| | | 84 | | { |
| | 138 | 85 | | } // do nothing |
| | | 86 | | |
| | | 87 | | void IOperationBehavior.ApplyClientBehavior(OperationDescription operationDescription, ClientOperation clientOpe |
| | | 88 | | { |
| | 0 | 89 | | } // do nothing |
| | | 90 | | |
| | | 91 | | void IOperationBehavior.ApplyDispatchBehavior(OperationDescription operationDescription, DispatchOperation dispa |
| | | 92 | | { |
| | 138 | 93 | | } // do nothing |
| | | 94 | | |
| | | 95 | | void IOperationBehavior.Validate(OperationDescription operationDescription) |
| | | 96 | | { |
| | 137 | 97 | | } // do nothing |
| | | 98 | | |
| | | 99 | | internal WebMessageBodyStyle GetBodyStyleOrDefault(WebMessageBodyStyle defaultStyle) |
| | | 100 | | { |
| | 552 | 101 | | if (IsBodyStyleSetExplicitly) |
| | | 102 | | { |
| | 344 | 103 | | return BodyStyle; |
| | | 104 | | } |
| | | 105 | | else |
| | | 106 | | { |
| | 208 | 107 | | return defaultStyle; |
| | | 108 | | } |
| | | 109 | | } |
| | | 110 | | |
| | 137 | 111 | | OperationContractAttribute IOperationContractAttributeProvider.GetOperationContractAttribute() => new OperationC |
| | | 112 | | } |
| | | 113 | | } |