private static WebMode GetWebMode(MethodDefinition interfaceMethod, CustomAttribute customAttribute) { WebMode webMode; var methodProperty = customAttribute.Properties.FirstOrDefault(x => x.Name == WcfAttributeConstants.Method); if (methodProperty.Name == WcfAttributeConstants.Method) { var argument = (string)methodProperty.Argument.Value; switch (argument.ToUpper()) { case WcfAttributeConstants.Method_Post: webMode = WebMode.Post; break; case WcfAttributeConstants.Method_Put: webMode = WebMode.Put; break; case WcfAttributeConstants.Method_Delete: webMode = WebMode.Delete; break; default: throw new NotSupportedException( string.Format("WebInvoke Method '{0}' is not supported on '{1}'", argument, interfaceMethod.FullName)); } } else { //default webMode = WebMode.Post; } return(webMode); }
private void ProcessWebAttribute() { // Find all web attributess var webGetAttribute = InterfaceMethod.CustomAttributes.FirstOrDefault(x => x.AttributeType.FullName == WcfAttributeConstants.WebGetAttribute); var webInvokeAttribute = InterfaceMethod.CustomAttributes.FirstOrDefault(x => x.AttributeType.FullName == WcfAttributeConstants.WebInvokeAttribute); if (webGetAttribute == null) { if (webInvokeAttribute == null) { webMode = WebMode.None; } else { webMode = GetWebMode(InterfaceMethod, webInvokeAttribute); requestFormat = GetRequestFormat(InterfaceMethod, webInvokeAttribute); responseFormat = GetResponseFormat(InterfaceMethod, webInvokeAttribute); uriTemplate = GetUriTemplate(InterfaceMethod, webInvokeAttribute); } } else { if (webInvokeAttribute == null) { webMode = WebMode.Get; responseFormat = GetResponseFormat(InterfaceMethod, webGetAttribute); uriTemplate = GetUriTemplate(InterfaceMethod, webGetAttribute); } else { throw new NotSupportedException( string.Format("Both WebGet and WebInvoke attributes are specified on the same method '{0}'", InterfaceMethod.FullName)); } } }
private static WebMode GetWebMode(MethodDefinition interfaceMethod, CustomAttribute customAttribute) { WebMode webMode; var methodProperty =customAttribute.Properties.FirstOrDefault(x => x.Name == WcfAttributeConstants.Method); if (methodProperty.Name == WcfAttributeConstants.Method) { var argument = (string) methodProperty.Argument.Value; switch (argument.ToUpper()) { case WcfAttributeConstants.Method_Post: webMode = WebMode.Post; break; case WcfAttributeConstants.Method_Put: webMode = WebMode.Put; break; case WcfAttributeConstants.Method_Delete: webMode = WebMode.Delete; break; default: throw new NotSupportedException( string.Format("WebInvoke Method '{0}' is not supported on '{1}'", argument, interfaceMethod.FullName)); } } else { //default webMode = WebMode.Post; } return webMode; }