Ejemplo n.º 1
0
        public object Retrieve(string serviceName, XmlRpcStruct args)
        {
            Console.WriteLine("Service \"{0}\"", serviceName);
            ProvidersManager providers = new ProvidersManager();
            Extractable service = null;
            try {
                service = providers.FindService(serviceName);
            }
            catch (InvalidNameException) {
                string msg = "The name of the service should be in the format NameSpace.ServiceName";
                throw new XmlRpcFaultException(32602, msg);
            }
            catch (ServiceNotFoundException) {
                string msg = String.Format("The service \"{0}\" does not exist on this server.", serviceName);
                throw new XmlRpcFaultException(32602, msg);
            }

            Console.WriteLine("Arguments (as strings):");
            StringDict arguments = new StringDict();
            foreach (DictionaryEntry keyval in args) {
                arguments.Add((string)keyval.Key, keyval.Value.ToString());
                Console.WriteLine("{0}=>{1}", keyval.Key, keyval.Value);
            }

            service.Extract(arguments);

            Console.WriteLine("Result: {0}", service.ToString());
            return service;
        }
Ejemplo n.º 2
0
    static void Main(string[] args)
    {
        if (args.Length == 0) {
            Console.WriteLine("Either pass --server to run as XML-RPC server mode, or pass " +
                              "\"ServiceName [arg, arg...]\" to run directly.");
            return;
        }

        if (args.Length > 0 && args[0] == "--server") {
            int port = 9996;
            BlockingXmlRpcServer server = new BlockingXmlRpcServer(port);
            server.Start();
        } else {
            ProvidersManager providers = new ProvidersManager();
            Extractable service = null;
            try {
                service = providers.FindService(args[0]);
            }
            catch (InvalidNameException) {
                Console.WriteLine("The name of the service should be in the format NameSpace.ServiceName");
                return;
            }
            catch (ServiceNotFoundException) {
                Console.WriteLine("The service {0} is not currently supported.", args[0]);
                return;
            }

            StringDict arguments = new StringDict();
            if (args.Length > 1)
                for (int i = 1; i < args.Length; i++) {
                    string[] name_val = args[i].Split("=".ToCharArray(), 2);
                    if (name_val.Length > 1)
                        arguments.Add(name_val[0], name_val[1]);
                    else
                        Console.WriteLine("Wrong argument format, ignored: {0}", args[i]);
                }

            service.Extract(arguments);
            Console.WriteLine (service.ToString());
        }
    }