CreateServiceInfo() публичный статический Метод

public static CreateServiceInfo ( Type type ) : XmlRpcServiceInfo
type System.Type
Результат XmlRpcServiceInfo
Пример #1
0
        public Array System__Method__Signature___(string MethodName)
        {
            //TODO: support overloaded methods
            XmlRpcServiceInfo svcInfo = XmlRpcServiceInfo.CreateServiceInfo(
                this.GetType());
            XmlRpcMethodInfo mthdInfo = svcInfo.GetMethod(MethodName);

            if (mthdInfo == null)
            {
                throw new XmlRpcFaultException("880",
                                               "Request for information on unsupported method");
            }
            if (mthdInfo.IsHidden)
            {
                throw new XmlRpcFaultException("881",
                                               "Information not available on this method");
            }
            //XmlRpcTypes.CheckIsXmlRpcMethod(mi);
            ArrayList alist = new ArrayList();

            alist.Add(XmlRpcServiceInfo.GetXmlRpcTypeString(mthdInfo.ReturnType));
            foreach (XmlRpcParameterInfo paramInfo in mthdInfo.Parameters)
            {
                alist.Add(XmlRpcServiceInfo.GetXmlRpcTypeString(paramInfo.Type));
            }
            string[]  types    = (string[])alist.ToArray(typeof(string));
            ArrayList retalist = new ArrayList();

            retalist.Add(types);
            Array retarray = retalist.ToArray(typeof(string[]));

            return(retarray);
        }
Пример #2
0
        public static void WriteDoc(HtmlTextWriter wrtr, Type type)
        {
            XmlRpcServiceInfo svcInfo = XmlRpcServiceInfo.CreateServiceInfo(type);

            wrtr.WriteFullBeginTag("html");
            wrtr.WriteLine();
            WriteHead(wrtr, svcInfo.Name);
            wrtr.WriteLine();
            WriteBody(wrtr, type);
            wrtr.WriteEndTag("html");
        }
Пример #3
0
        public string[] System__List__Methods___()
        {
            XmlRpcServiceInfo svcInfo = XmlRpcServiceInfo.CreateServiceInfo(
                this.GetType());
            ArrayList alist = new ArrayList();

            foreach (XmlRpcMethodInfo mthdInfo in svcInfo.Methods)
            {
                if (!mthdInfo.IsHidden)
                {
                    alist.Add(mthdInfo.XmlRpcName);
                }
            }
            return((String[])alist.ToArray(typeof(string)));
        }
Пример #4
0
        Header[] GetChannelHeaders(
            ITransportHeaders requestHeaders,
            XmlRpcRequest xmlRpcReq,
            Type svcType)
        {
            string            requestUri = (string)requestHeaders["__RequestUri"];
            XmlRpcServiceInfo svcInfo    = XmlRpcServiceInfo.CreateServiceInfo(svcType);
            ArrayList         hdrList    = new ArrayList();

            hdrList.Add(new Header("__Uri", requestUri));
            hdrList.Add(new Header("__TypeName", svcType.AssemblyQualifiedName));
            hdrList.Add(new Header("__MethodName",
                                   svcInfo.GetMethodName(xmlRpcReq.method)));
            hdrList.Add(new Header("__Args", xmlRpcReq.args));
            return((Header[])hdrList.ToArray(typeof(Header)));
        }
Пример #5
0
        public string System__Method__Help___(string MethodName)
        {
            //TODO: support overloaded methods?
            XmlRpcServiceInfo svcInfo = XmlRpcServiceInfo.CreateServiceInfo(
                this.GetType());
            XmlRpcMethodInfo mthdInfo = svcInfo.GetMethod(MethodName);

            if (mthdInfo == null)
            {
                throw new XmlRpcFaultException("880",
                                               "Request for information on unsupported method");
            }
            if (mthdInfo.IsHidden)
            {
                throw new XmlRpcFaultException("881",
                                               "Information not available for this method");
            }
            return(mthdInfo.Doc);
        }
Пример #6
0
        public static void WriteType(
            HtmlTextWriter wrtr,
            Type type)
        {
            ArrayList structs = new ArrayList();

            wrtr.WriteBeginTag("div");
            wrtr.WriteAttribute("id", "content");
            wrtr.Write(HtmlTextWriter.TagRightChar);
            wrtr.WriteLine();

            XmlRpcServiceInfo svcInfo =
                XmlRpcServiceInfo.CreateServiceInfo(type);

            wrtr.WriteBeginTag("p");
            wrtr.WriteAttribute("class", "heading1");
            wrtr.Write(HtmlTextWriter.TagRightChar);
            wrtr.Write(svcInfo.Name);
            wrtr.WriteEndTag("p");
            wrtr.WriteFullBeginTag("br");
            wrtr.WriteEndTag("br");
            wrtr.WriteLine();

            if (svcInfo.Doc != "")
            {
                wrtr.WriteBeginTag("p");
                wrtr.WriteAttribute("class", "intro");
                wrtr.Write(HtmlTextWriter.TagRightChar);
                wrtr.Write(svcInfo.Doc);
                wrtr.WriteEndTag("p");
                wrtr.WriteLine();
            }
            wrtr.WriteBeginTag("p");
            wrtr.WriteAttribute("class", "intro");
            wrtr.Write(HtmlTextWriter.TagRightChar);
            wrtr.Write("The following methods are supported:");
            wrtr.WriteEndTag("p");
            wrtr.WriteLine();

            wrtr.WriteFullBeginTag("ul");
            wrtr.WriteLine();
            foreach (XmlRpcMethodInfo mthdInfo in svcInfo.Methods)
            {
                if (!mthdInfo.IsHidden)
                {
                    wrtr.WriteFullBeginTag("li");
                    wrtr.WriteBeginTag("a");
                    wrtr.WriteAttribute("href", "#" + mthdInfo.XmlRpcName);
                    wrtr.Write(HtmlTextWriter.TagRightChar);
                    wrtr.Write(mthdInfo.XmlRpcName);
                    wrtr.WriteEndTag("a");
                    wrtr.WriteEndTag("li");
                    wrtr.WriteLine();
                }
            }

            wrtr.WriteEndTag("ul");
            wrtr.WriteLine();

            foreach (XmlRpcMethodInfo mthdInfo in svcInfo.Methods)
            {
                if (mthdInfo.IsHidden == false)
                {
                    WriteMethod(wrtr, mthdInfo, structs);
                }
            }

            for (int j = 0; j < structs.Count; j++)
            {
                WriteStruct(wrtr, structs[j] as Type, structs);
            }

            wrtr.WriteEndTag("div");
            wrtr.WriteLine();
        }
Пример #7
0
        public XmlRpcRequest DeserializeRequest(XmlReader rdr, Type svcType)
        {
            try
            {
                XmlRpcRequest      request = new XmlRpcRequest();
                IEnumerator <Node> iter    = new XmlRpcParser().ParseRequest(rdr).GetEnumerator();

                iter.MoveNext();
                string methodName = (iter.Current as MethodName).Name;
                request.method = methodName;

                request.mi = null;
                ParameterInfo[] pis = null;
                if (svcType != null)
                {
                    // retrieve info for the method which handles this XML-RPC method
                    XmlRpcServiceInfo svcInfo
                               = XmlRpcServiceInfo.CreateServiceInfo(svcType);
                    request.mi = svcInfo.GetMethodInfo(request.method);
                    // if a service type has been specified and we cannot find the requested
                    // method then we must throw an exception
                    if (request.mi == null)
                    {
                        string msg = String.Format("unsupported method called: {0}",
                                                   request.method);
                        throw new XmlRpcUnsupportedMethodException(msg);
                    }
                    // method must be marked with XmlRpcMethod attribute
                    Attribute attr = Attribute.GetCustomAttribute(request.mi,
                                                                  typeof(XmlRpcMethodAttribute));
                    if (attr == null)
                    {
                        throw new XmlRpcMethodAttributeException(
                                  "Method must be marked with the XmlRpcMethod attribute.");
                    }
                    pis = request.mi.GetParameters();
                }

                bool gotParams = iter.MoveNext();
                if (!gotParams)
                {
                    if (svcType != null)
                    {
                        if (pis.Length == 0)
                        {
                            request.args = new object[0];
                            return(request);
                        }
                        else
                        {
                            throw new XmlRpcInvalidParametersException(
                                      "Method takes parameters and params element is missing.");
                        }
                    }
                    else
                    {
                        request.args = new object[0];
                        return(request);
                    }
                }

                int paramsPos = pis != null?GetParamsPos(pis) : -1;

                Type paramsType = null;
                if (paramsPos != -1)
                {
                    paramsType = pis[paramsPos].ParameterType.GetElementType();
                }
                int minParamCount = pis == null ? int.MaxValue
          : (paramsPos == -1 ? pis.Length : paramsPos);
                MappingStack  mappingStack  = new MappingStack("request");
                MappingAction mappingAction = MappingAction.Error;
                var           objs          = new List <object>();
                var           paramsObjs    = new List <object>();
                int           paramCount    = 0;


                while (iter.MoveNext())
                {
                    paramCount++;
                    if (svcType != null && paramCount > minParamCount && paramsPos == -1)
                    {
                        throw new XmlRpcInvalidParametersException(
                                  "Request contains too many param elements based on method signature.");
                    }
                    if (paramCount <= minParamCount)
                    {
                        if (svcType != null)
                        {
                            mappingStack.Push(String.Format("parameter {0}", paramCount));
                            // TODO: why following commented out?
                            //          parseStack.Push(String.Format("parameter {0} mapped to type {1}",
                            //            i, pis[i].ParameterType.Name));
                            var obj = MapValueNode(iter,
                                                   pis[paramCount - 1].ParameterType, mappingStack, mappingAction);
                            objs.Add(obj);
                        }
                        else
                        {
                            mappingStack.Push(String.Format("parameter {0}", paramCount));
                            var obj = MapValueNode(iter, null, mappingStack, mappingAction);
                            objs.Add(obj);
                        }
                        mappingStack.Pop();
                    }
                    else
                    {
                        mappingStack.Push(String.Format("parameter {0}", paramCount + 1));
                        var paramsObj = MapValueNode(iter, paramsType, mappingStack, mappingAction);
                        paramsObjs.Add(paramsObj);
                        mappingStack.Pop();
                    }
                }

                if (svcType != null && paramCount < minParamCount)
                {
                    throw new XmlRpcInvalidParametersException(
                              "Request contains too few param elements based on method signature.");
                }

                if (paramsPos != -1)
                {
                    Object[] args = new Object[1];
                    args[0] = paramCount - minParamCount;
                    Array varargs = (Array)Activator.CreateInstance(pis[paramsPos].ParameterType, args);
                    for (int i = 0; i < paramsObjs.Count; i++)
                    {
                        varargs.SetValue(paramsObjs[i], i);
                    }
                    objs.Add(varargs);
                }
                request.args = objs.ToArray();
                return(request);
            }
            catch (XmlException ex)
            {
                throw new XmlRpcIllFormedXmlException("Request contains invalid XML", ex);
            }
        }
Пример #8
0
 public void DupXmlRpcNames()
 {
     XmlRpcServiceInfo svcinfo = XmlRpcServiceInfo.CreateServiceInfo(typeof(IDupXmlRpcNames));
 }
Пример #9
0
        public void DerivedInterfaces()
        {
            XmlRpcServiceInfo svcinfo = XmlRpcServiceInfo.CreateServiceInfo(typeof(FooBar));

            Assert.AreEqual(2, svcinfo.Methods.Length);
        }
Пример #10
0
 public void PropertyMember()
 {
     XmlRpcServiceInfo info = XmlRpcServiceInfo.CreateServiceInfo(typeof(struct3));
 }