• 【代码保留】WebService发布本地磁盘信息


    今天有人问到如何在服务器A的WebApplication中访问服务器B的磁盘信息(文件Server)。

    方案很多啦:

    FTP协议访问、WebService发布磁盘信息、WCF构建等……

    随手就写了WebService的Demo,蛮放着……

    (未处理的东西多啦,特别是安全性的地方……)

    ///////////////////////code///////////////////////////////////////////////////

    using System.ComponentModel;
    using System.Web.Services;
    using System.IO;
    using System;

    namespace WebServiceFileDirectory
    {
        /// <summary>
        /// Summary description for Service1
        /// </summary>
        [WebService(Namespace = "http://volnet.cnblogs.com/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        [ToolboxItem(false)]
        // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
        // [System.Web.Script.Services.ScriptService]
        public class ServiceFileDirectory : System.Web.Services.WebService
        {
            private static readonly string path = System.Configuration.ConfigurationManager.AppSettings["directory"];

            [WebMethod]
            public string[] GetDirectories()
            {
                if (MakeSurePath() == true)
                {
                    return Directory.GetDirectories(path);
                }
                return null;
            }

            [WebMethod]
            public string[] GetFiles()
            {
                if (MakeSurePath() == true)
                {
                    return Directory.GetFiles(path);
                }
                return null;
            }

            private bool? isCorrectPath = null;
            /// <summary>
            /// 确保路径正确
            /// </summary>
            /// <returns></returns>
            private bool? MakeSurePath()
            {
                try
                {
                    if (isCorrectPath.HasValue == false)
                    {
                        if (!Directory.Exists(path))
                        {
                            Directory.CreateDirectory(path);
                        }
                        isCorrectPath = true;
                    }
                }
                catch
                {
                    isCorrectPath = false;
                }
                finally
                {
                }
                return isCorrectPath;
            }
        }
    }

    //Tester:

    protected void btnGetFiles_Click(object sender, EventArgs e)
    {
        FileSystem.ServiceFileDirectory sf = new WebApplicationTester.FileSystem.ServiceFileDirectory();
        string[] files = sf.GetFiles();
        string result= string.Empty;
        foreach (string str in files)
        {
            result += str + "<BR>";
        }
        this.Response.Write(result);
    }

  • 相关阅读:
    牛客网-《剑指offer》-包含min函数的栈
    牛客网-《剑指offer》-调整数组顺序使奇数位于偶数前面
    Gate Decorator: Global Filter Pruning Method for Accelerating Deep Convolutional Neural Networks
    pytorch数据预处理错误
    python2 pickle.dump生成的文件,python3 pickle.load怎么加载
    CSAGAN的几大重点
    BicycleGAN: Toward Multimodal Image-to-Image Translation
    StarGAN: Unified Generative Adversarial Networks for Multi-Domain Image-to-Image Translation
    MUNIT:Multimodal Unsupervised Image-to-Image Translation
    SAGAN:Self-Attention Generative Adversarial Networks
  • 原文地址:https://www.cnblogs.com/volnet/p/974786.html
Copyright © 2020-2023  润新知