コード例 #1
0
 public Stream Invoke(Stream requestStream)
 {
     try
     {
         XmlRpcSerializer       serializer  = new XmlRpcSerializer();
         Type                   type        = this.GetType();
         XmlRpcServiceAttribute serviceAttr = (XmlRpcServiceAttribute)
                                              Attribute.GetCustomAttribute(this.GetType(),
                                                                           typeof(XmlRpcServiceAttribute));
         if (serviceAttr != null)
         {
             if (serviceAttr.XmlEncoding != null)
             {
                 serializer.XmlEncoding = Encoding.GetEncoding(serviceAttr.XmlEncoding);
             }
             serializer.UseIntTag      = serviceAttr.UseIntTag;
             serializer.UseStringTag   = serviceAttr.UseStringTag;
             serializer.UseIndentation = serviceAttr.UseIndentation;
             serializer.Indentation    = serviceAttr.Indentation;
         }
         XmlRpcRequest xmlRpcReq
             = serializer.DeserializeRequest(requestStream, this.GetType());
         XmlRpcResponse xmlRpcResp     = Invoke(xmlRpcReq);
         Stream         responseStream = new MemoryStream();
         serializer.SerializeResponse(responseStream, xmlRpcResp);
         responseStream.Seek(0, SeekOrigin.Begin);
         return(responseStream);
     }
     catch (Exception ex)
     {
         XmlRpcFaultException fex;
         if (ex is XmlRpcException)
         {
             fex = new XmlRpcFaultException(0, ((XmlRpcException)ex).Message);
         }
         else if (ex is XmlRpcFaultException)
         {
             fex = (XmlRpcFaultException)ex;
         }
         else
         {
             fex = new XmlRpcFaultException(0, ex.Message);
         }
         XmlRpcSerializer serializer     = new XmlRpcSerializer();
         Stream           responseStream = new MemoryStream();
         serializer.SerializeFaultResponse(responseStream, fex);
         responseStream.Seek(0, SeekOrigin.Begin);
         return(responseStream);
     }
 }
コード例 #2
0
        public void HandleHttpRequest(
            IHttpRequest httpReq,
            IHttpResponse httpResp)
        {
            // GET has its own handler because it can be used to return a
            // HTML description of the service
            if (httpReq.HttpMethod == "GET")
            {
                XmlRpcServiceAttribute svcAttr = (XmlRpcServiceAttribute)
                                                 Attribute.GetCustomAttribute(GetType(), typeof(XmlRpcServiceAttribute));
                if (svcAttr != null && svcAttr.AutoDocumentation == false)
                {
                    HandleUnsupportedMethod(httpReq, httpResp);
                }
                else
                {
                    bool autoDocVersion = true;
                    if (svcAttr != null)
                    {
                        autoDocVersion = svcAttr.AutoDocVersion;
                    }
                    HandleGET(httpReq, httpResp, autoDocVersion);
                }
                return;
            }
            // calls on service methods are via POST
            if (httpReq.HttpMethod != "POST")
            {
                HandleUnsupportedMethod(httpReq, httpResp);
                return;
            }
            //Context.Response.AppendHeader("Server", "XML-RPC.NET");
            // process the request
            Stream responseStream = Invoke(httpReq.InputStream);

            httpResp.ContentType = "text/xml";
            if (!httpResp.SendChunked)
            {
                httpResp.ContentLength = responseStream.Length;
            }
            Stream respStm = httpResp.OutputStream;

            Util.CopyStream(responseStream, respStm);
            respStm.Flush();
        }
コード例 #3
0
        public static XmlRpcServiceInfo CreateServiceInfo(Type type)
        {
            XmlRpcServiceInfo svcInfo = new XmlRpcServiceInfo();
            // extract service info
            XmlRpcServiceAttribute svcAttr = (XmlRpcServiceAttribute)
                                             Attribute.GetCustomAttribute(type, typeof(XmlRpcServiceAttribute));

            if (svcAttr != null && svcAttr.Description != "")
            {
                svcInfo.doc = svcAttr.Description;
            }
            if (svcAttr != null && svcAttr.Name != "")
            {
                svcInfo.Name = svcAttr.Name;
            }
            else
            {
                svcInfo.Name = type.Name;
            }
            // extract method info
            Hashtable methods = new Hashtable();

            foreach (Type itf in type.GetInterfaces())
            {
                XmlRpcServiceAttribute itfAttr = (XmlRpcServiceAttribute)
                                                 Attribute.GetCustomAttribute(itf, typeof(XmlRpcServiceAttribute));
                if (itfAttr != null)
                {
                    svcInfo.doc = itfAttr.Description;
                }
#if (!COMPACT_FRAMEWORK)
                InterfaceMapping imap = type.GetInterfaceMap(itf);
                foreach (MethodInfo mi in imap.InterfaceMethods)
                {
                    ExtractMethodInfo(methods, mi, itf);
                }
#else
                foreach (MethodInfo mi in itf.GetMethods())
                {
                    ExtractMethodInfo(methods, mi, itf);
                }
#endif
            }

            foreach (MethodInfo mi in type.GetMethods())
            {
                ArrayList mthds = new ArrayList();
                mthds.Add(mi);
                MethodInfo curMi = mi;
                while (true)
                {
                    MethodInfo baseMi = curMi.GetBaseDefinition();
                    if (baseMi.DeclaringType == curMi.DeclaringType)
                    {
                        break;
                    }
                    mthds.Insert(0, baseMi);
                    curMi = baseMi;
                }
                foreach (MethodInfo mthd in mthds)
                {
                    ExtractMethodInfo(methods, mthd, type);
                }
            }
            svcInfo.methodInfos = new XmlRpcMethodInfo[methods.Count];
            methods.Values.CopyTo(svcInfo.methodInfos, 0);
            Array.Sort(svcInfo.methodInfos);
            return(svcInfo);
        }