Example #1
0
 void GetWebGetAndInvoke(OperationDescription od, out WebGetAttribute get, out WebInvokeAttribute invoke)
 {
     get = od.Behaviors.Find<WebGetAttribute>();
     invoke = od.Behaviors.Find<WebInvokeAttribute>();
     if (get == null && invoke == null)
     {
         // default is POST
         invoke = new WebInvokeAttribute();
     }
 }
Example #2
0
		public void IOperationBehaviorMethods ()
		{
			IOperationBehavior oper = new WebGetAttribute ();
			var pl = new BindingParameterCollection ();
			var od = ContractDescription.GetContract (typeof (TestService)).Operations [0];
			oper.AddBindingParameters (od, pl);
			Assert.AreEqual (0, pl.Count, "#1");

			// yeah it really does nothing.
			oper.AddBindingParameters (null, null);

			oper.ApplyClientBehavior (od, null);
			oper.ApplyDispatchBehavior (od, null);
			oper.Validate (od);
		}
 private static void EnsureOk(WebGetAttribute wga, WebInvokeAttribute wia, OperationDescription od)
 {
     if (wga != null && wia != null)
     {
         throw new InvalidOperationException();
     }
 }
Example #4
0
 WebMessageBodyStyle GetBodyStyle(WebGetAttribute get, WebInvokeAttribute invoke)
 {
     if (get != null)
     {
         return get.BodyStyle;
     }
     return invoke.BodyStyle;
 }
Example #5
0
        private string GetMethod(WebGetAttribute get, WebInvokeAttribute invoke)
        {
            if (get != null) return "GET";
            if (invoke != null && !string.IsNullOrEmpty(invoke.Method)) return invoke.Method;
            return "POST";

        }
Example #6
0
 private string GetResponseFormat(WebGetAttribute get, WebInvokeAttribute invoke, OperationDescription od)
 {
     if (IsResponseStream(od))
     {
         return "binary";
     }
     if (get != null && get.IsResponseFormatSetExplicitly) return get.ResponseFormat.ToString();
     if (invoke != null && invoke.IsResponseFormatSetExplicitly) return invoke.ResponseFormat.ToString();
     return this.Behavior.DefaultOutgoingResponseFormat.ToString();
 }
Example #7
0
 private string GetUriTemplate(WebGetAttribute get, WebInvokeAttribute invoke, OperationDescription od)
 {
     if (get != null)
     {
         if (get.UriTemplate != null)
         {
             return get.UriTemplate;
         }
         else
         {
             StringBuilder sb = new StringBuilder(od.Name);
             if (!IsUntypedMessage(od.Messages[0]))
             {
                 sb.Append("?");
                 foreach (MessagePartDescription mpd in od.Messages[0].Body.Parts)
                 {
                     string parameterName = mpd.Name;
                     sb.Append(parameterName);
                     sb.Append("={");
                     sb.Append(parameterName);
                     sb.Append("}&");
                 }
                 sb.Remove(sb.Length - 1, 1);
             }
             return sb.ToString();
         }
     }
     if (invoke.UriTemplate != null)
     {
         return invoke.UriTemplate;
     }
     else
     {
         return od.Name;
     }
 }
Example #8
0
 static void EnsureOk(WebGetAttribute wga, WebInvokeAttribute wia, OperationDescription od)
 {
     if (wga != null && wia != null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
             SR2.GetString(SR2.MultipleWebAttributes, od.Name, od.DeclaringContract.Name)));
     }
 }
 private static void EnsureOneOneWebAttribute(WebGetAttribute webGet, WebInvokeAttribute webInvoke, HttpOperationDescription operation)
 {
     if (webGet != null && webInvoke != null)
     {
         throw Fx.Exception.AsError(
             new InvalidOperationException(
                 SR.MultipleWebAttributes(
                     operation.Name,
                     operation.DeclaringContract.Name,
                     webGetAttributeType.Name,
                     webInvokeAttributeType.Name)));
     }
 }
Example #10
0
        /// <summary>
        /// Serialize a .NET method definition in json.
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="method"></param>
        /// <param name="getAttr"></param>
        /// <param name="invokAttr"></param>
        private void serializeMethod(JsonWriter writer, MethodInfo method, WebGetAttribute getAttr, WebInvokeAttribute invokAttr)
        {
            writer.WritePropertyName(method.Name);
            writer.WriteStartObject();

            writer.WritePropertyName("transport");
            writer.WriteValue(getAttr != null ? "GET" : invokAttr.Method);

            writer.WritePropertyName("target");
            writer.WriteValue(method.Name);

            writer.WritePropertyName("envelope");
            writer.WriteValue(getAttr != null ? "URL" : "JSON");

            writer.WritePropertyName("parameters");

            writer.WriteStartArray();

            ParameterInfo[] prams = method.GetParameters();
            foreach (ParameterInfo prm in method.GetParameters())
            {
                writer.WriteStartObject();

                writer.WritePropertyName("name");
                writer.WriteValue(prm.Name);

                writer.WritePropertyName("type");
                writer.WriteValue(prm.ParameterType.ToString());

                writer.WriteEndObject();
            }

            writer.WriteEndArray();
            writer.WriteEndObject();
        }
Example #11
0
 private static void CheckWebInvokeAndWebGet(WebInvokeAttribute wia, WebGetAttribute wga, OperationDescription operationDescription)
 {
     if (wga != null && wia != null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(DiagnosticUtility.GetString(SR.OperationContractConflictsWebGetOrWebInvoke, operationDescription.Name)));
     }
 }