1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
|
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
namespace System.ServiceModel.Web
{
using System;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
using System.ServiceModel.Channels;
using System.ServiceModel.Web;
using System.ServiceModel.Administration;
[AttributeUsage(AttributeTargets.Method)]
public sealed class WebInvokeAttribute : Attribute, IOperationContractAttributeProvider, IOperationBehavior, IWmiInstanceProvider
{
WebMessageBodyStyle bodyStyle;
bool isBodyStyleDefined;
bool isRequestMessageFormatSet;
bool isResponseMessageFormatSet;
string method; // http verb
WebMessageFormat requestMessageFormat;
WebMessageFormat responseMessageFormat;
string uriTemplate; // Note: HttpTransferEndpointBehavior interprets uriTemplate as: null means 'no opinion', whereas string.Empty means relative path of ""
public WebInvokeAttribute()
{
}
public WebMessageBodyStyle BodyStyle
{
get { return this.bodyStyle; }
set
{
if (!WebMessageBodyStyleHelper.IsDefined(value))
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value"));
}
this.bodyStyle = value;
this.isBodyStyleDefined = true;
}
}
public bool IsBodyStyleSetExplicitly
{
get { return this.isBodyStyleDefined; }
}
public bool IsRequestFormatSetExplicitly
{
get { return this.isRequestMessageFormatSet; }
}
public bool IsResponseFormatSetExplicitly
{
get { return this.isResponseMessageFormatSet; }
}
public string Method
{ get { return this.method; } set { this.method = value; } }
public WebMessageFormat RequestFormat
{
get
{
return this.requestMessageFormat;
}
set
{
if (!WebMessageFormatHelper.IsDefined(value))
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value"));
}
this.requestMessageFormat = value;
this.isRequestMessageFormatSet = true;
}
}
public WebMessageFormat ResponseFormat
{
get
{
return this.responseMessageFormat;
}
set
{
if (!WebMessageFormatHelper.IsDefined(value))
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value"));
}
this.responseMessageFormat = value;
this.isResponseMessageFormatSet = true;
}
}
public string UriTemplate
{ get { return this.uriTemplate; } set { this.uriTemplate = value; } }
void IOperationBehavior.AddBindingParameters(OperationDescription operationDescription, BindingParameterCollection bindingParameters)
{
} // do nothing
void IOperationBehavior.ApplyClientBehavior(OperationDescription operationDescription, ClientOperation clientOperation)
{
} // do nothing
void IOperationBehavior.ApplyDispatchBehavior(OperationDescription operationDescription, DispatchOperation dispatchOperation)
{
} // do nothing
void IOperationBehavior.Validate(OperationDescription operationDescription)
{
} // do nothing
internal WebMessageBodyStyle GetBodyStyleOrDefault(WebMessageBodyStyle defaultStyle)
{
if (this.IsBodyStyleSetExplicitly)
{
return this.BodyStyle;
}
else
{
return defaultStyle;
}
}
void IWmiInstanceProvider.FillInstance(IWmiInstance wmiInstance)
{
if (wmiInstance == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("wmiInstance");
}
wmiInstance.SetProperty("BodyStyle", this.BodyStyle.ToString());
wmiInstance.SetProperty("IsBodyStyleSetExplicitly", this.IsBodyStyleSetExplicitly.ToString());
wmiInstance.SetProperty("RequestFormat", this.RequestFormat.ToString());
wmiInstance.SetProperty("IsRequestFormatSetExplicitly", this.IsRequestFormatSetExplicitly.ToString());
wmiInstance.SetProperty("ResponseFormat", this.ResponseFormat.ToString());
wmiInstance.SetProperty("IsResponseFormatSetExplicitly", this.IsResponseFormatSetExplicitly.ToString());
wmiInstance.SetProperty("UriTemplate", this.UriTemplate);
wmiInstance.SetProperty("Method", this.Method);
}
string IWmiInstanceProvider.GetInstanceType()
{
return "WebInvokeAttribute";
}
OperationContractAttribute IOperationContractAttributeProvider.GetOperationContractAttribute()
{
return new OperationContractAttribute();
}
}
}
|