示例#1
0
        private string GetMethodParameter(BusinessMethodModel model, string kind, string method)
        {
            StringBuilder buider          = new StringBuilder();
            var           parametersCount = model.ParametersCount;

            if (parametersCount > 0)
            {
                buider.Append("<b>INPUT</b> -><br/>");
            }
            foreach (var p in model.Parameters)
            {
                if (!string.IsNullOrEmpty(kind) && !string.IsNullOrEmpty(method))
                {
                    buider.Append(GetTypeDetail(p.Name, p.ParameterType, 1));
                }
                else
                {
                    buider.AppendFormat(string.Format("&nbsp;&nbsp;&nbsp;&nbsp;&lt;{0} : {1}&gt;", p.Name, GetTypeName(p.ParameterType)) + "<br/>");
                }
            }
            if (parametersCount > 0)
            {
                buider.Append("<hr/>");
            }
            var value = string.Format("<b>OUTPUT</b> -> {0}<br/>", GetTypeName(model.Method.ReturnType));

            buider.Append("<font color=\"#336699\">").Append(value);
            if (!string.IsNullOrEmpty(kind) && !string.IsNullOrEmpty(method))
            {
                buider.Append(GetTypeDetail(null, model.Method.ReturnType, 1));
            }
            buider.Append("</font>");

            return(buider.ToString());
        }
示例#2
0
        /// <summary>
        /// 方法调用
        /// </summary>
        /// <param name="kind"></param>
        /// <param name="method"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public object Invoke(string kind, string method, NameValueCollection parameters, out Type retType)
        {
            WebOperationContext context  = WebOperationContext.Current;
            BusinessMethodModel metadata = pool.FindMethod(kind, method);

            //返回类型
            retType = metadata.Method.ReturnType;

            //处理请求类型
            if (metadata.HttpMethod == HttpMethod.POST && context.IncomingRequest.Method.ToUpper() == "GET")
            {
                throw new RESTfulException((int)HttpStatusCode.MethodNotAllowed, "Resources can only by the [" + metadata.HttpMethod + "] way to acquire.");
            }

            //实例对象
            object instance = null;

            try
            {
                //调用方法
                object[] arguments = ParameterHelper.Convert(metadata.Parameters, parameters);
                instance = register.Resolve(metadata.Service);
                return(DynamicCalls.GetMethodInvoker(metadata.Method)(instance, arguments));
            }
            finally
            {
                register.Release(instance);
            }
        }
示例#3
0
        private string CreateAnchorHtml(Uri requestUri, BusinessKindModel e, BusinessMethodModel model, List <string> plist, HttpMethod mode, string format)
        {
            string url = string.Empty;

            if (mode == HttpMethod.GET && plist.Count > 0)
            {
                url = string.Format("/{0}.{1}.{2}?{3}", e.Name, model.Name, format, string.Join("&", plist.ToArray()));
            }
            else
            {
                url = string.Format("/{0}.{1}.{2}", e.Name, model.Name, format);
            }

            if (!string.IsNullOrEmpty(requestUri.Query))
            {
                if (url.IndexOf('?') >= 0)
                {
                    url += "&" + requestUri.Query.Substring(1);
                }
                else
                {
                    url += requestUri.Query;
                }
            }

            if (format == "jsonp")
            {
                if (url.IndexOf('?') >= 0)
                {
                    url += "&callback={callback}";
                }
                else
                {
                    url += "?callback={callback}";
                }
            }

            return(string.Format("<a rel=\"operation\" target=\"_blank\" title=\"{0}\" href=\"{0}\">{0}</a> 处的服务", url));
        }
        private string CreateAnchorHtml(Uri requestUri, BusinessKindModel e, BusinessMethodModel model, List<string> plist, HttpMethod mode, string format)
        {
            string url = string.Empty;
            if (mode == HttpMethod.GET && plist.Count > 0)
                url = string.Format("/{0}.{1}.{2}?{3}", e.Name, model.Name, format, string.Join("&", plist.ToArray()));
            else
                url = string.Format("/{0}.{1}.{2}", e.Name, model.Name, format);

            if (!string.IsNullOrEmpty(requestUri.Query))
            {
                if (url.IndexOf('?') >= 0)
                    url += "&" + requestUri.Query.Substring(1);
                else
                    url += requestUri.Query;
            }

            if (format == "jsonp")
            {
                if (url.IndexOf('?') >= 0)
                    url += "&callback={callback}";
                else
                    url += "?callback={callback}";
            }

            return string.Format("<a rel=\"operation\" target=\"_blank\" title=\"{0}\" href=\"{0}\">{0}</a> 处的服务", url);
        }
        private string GetMethodParameter(BusinessMethodModel model, string kind, string method)
        {
            StringBuilder buider = new StringBuilder();
            var parametersCount = model.ParametersCount;
            if (parametersCount > 0) buider.Append("<b>INPUT</b> -><br/>");
            foreach (var p in model.Parameters)
            {
                if (!string.IsNullOrEmpty(kind) && !string.IsNullOrEmpty(method))
                    buider.Append(GetTypeDetail(p.Name, p.ParameterType, 1));
                else
                    buider.AppendFormat(string.Format("&nbsp;&nbsp;&nbsp;&nbsp;&lt;{0} : {1}&gt;", p.Name, GetTypeName(p.ParameterType)) + "<br/>");
            }
            if (parametersCount > 0) buider.Append("<hr/>");
            var value = string.Format("<b>OUTPUT</b> -> {0}<br/>", GetTypeName(model.Method.ReturnType));
            buider.Append("<font color=\"#336699\">").Append(value);
            if (!string.IsNullOrEmpty(kind) && !string.IsNullOrEmpty(method))
                buider.Append(GetTypeDetail(null, model.Method.ReturnType, 1));
            buider.Append("</font>");

            return buider.ToString();
        }