Example #1
0
        /// <summary>
        /// Extension method to support retrieving Data Service Operations that support
        /// primitive values.
        /// </summary>
        /// <typeparam name="T">The expected data type.</typeparam>
        /// <param name="ctx">The Type to be extended (DataServiceContext).</param>
        /// <param name="uri">The address of the operation (with parameters if used)</param>
        /// <param name="callback">The callback.</param>
        /// <param name="state">State to be communicated back to the user.</param>
        /// <returns>An IAsyncResult.</returns>
        public static IAsyncResult BeginExecuteNonEntityOperation <T>(this DataServiceContext ctx, Uri uri, AsyncCallback callback, object state)
        {
            // Since I can't figure out how to limit the type to primitives, i'll do it with a runtime check
            if (!typeof(T).IsPrimitive && typeof(T) != typeof(string))
            {
                throw new DataServiceClientException("BeginExecuteForPrimitives cannot be used with types that are not primatives or String type.");
            }

            // Convert the Uri to use the Context's URI Base
            uri = BuildUri(ctx.BaseUri, uri);

            // Build the request to make our specific request
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);

            request.Method = "GET";
            request.Accept = "application/atom+xml,application/xml";
            //request.Headers[HttpRequestHeader.AcceptCharset] = "UTF-8";
            request.Headers["DataServiceVersion"]    = "1.0;Silverlight";
            request.Headers["MaxDataServiceVersion"] = "1.0;Silverlight";

            NonEntityOperationResult result = new NonEntityOperationResult(ctx, request, callback, state);

            result.BeginExecute();

            return(result);
        }