C#应用程序当中,调用了web services ,然后在目录下就有一个和应用程序名称相同的 .exe.config文件,里面有webservices连接信息,现在我是想隐藏这个.exe.config文件,当然不是简单的文件隐藏,请问有什么办法没有?在线等了,不好意思,我只有19分了。

解决方案 »

  1.   

    像WCF可以在代码里面设置的,不知道webservices可不可以的
      

  2.   

    不用vs自己生成的配置文件
    webservices连接信息写在程序里
    或者写在系统某个目录里
      

  3.   

    WindowsApplication143.exeusing System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Diagnostics;
    using System.IO;
    using System.Xml;namespace WindowsApplication143
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();            XmlDocument Doc = new XmlDocument();
                Doc.Load(Path.GetTempPath() + "app.config");            MessageBox.Show(Doc.SelectSingleNode("/configuration/appSettings/add[@key=\"a\"]")
                    .Attributes["value"].InnerText);  
            }
        }
    }WindowsApplication143.exe的App.config
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <appSettings>
        <add key ="a" value ="1"/>
      </appSettings> 
    </configuration>using System;
    using System.Collections.Generic;
    using System.Text;
    using System.IO;aaa.exe
    namespace aaa
    {
        class Program
        {
            static void Main(string[] args)
            {
                FileStream FS1 = File.Open("WindowsApplication143.exe", FileMode.Open);
                
                if (args[0] == "E")
                {
                    FileStream FS2 = File.Open("WindowsApplication143.exe.config", FileMode.Open);                FS1.Seek(0, SeekOrigin.End);
                    
                    for (int i = 0; i < FS2.Length; i++)
                        FS1.WriteByte((byte)FS2.ReadByte());                long L = FS2.Length;
                    String S = L.ToString();
                    while (S.Length < 8)
                        S = "0" + S;
                    byte[] Bytes = Encoding.ASCII.GetBytes(S);
                    for(int i=0;i<8;i++)
                        FS1.WriteByte(Bytes[i]);                FS2.Close();
                    File.Delete("WindowsApplication143.exe.config");
                }
                else
                {
                    FS1.Seek(-8, SeekOrigin.End);                byte[] Bytes = new byte[8];
                    for (int i = 0; i < 8; i++)
                        Bytes[i] = (byte)FS1.ReadByte();
                    String S = Encoding.ASCII.GetString(Bytes);
                    long L=Convert.ToInt64(S);                FS1.Seek(-L-8, SeekOrigin.Current);                FileStream FS2 = File.Create(Path.GetTempPath() + "App.config");                for (long i = 0; i < L; i++)
                        FS2.WriteByte((byte)FS1.ReadByte());                FS2.Close();
                }            FS1.Close();
            }
        }
    }都放在c:\下,运行 aaa E 
    把WindowsApplication143.exe和App.Config合并到一起
    运行时
    运行aaa DE
    把WindowsApplication143.exe和App.Config分离,然后把App.Config放在临时目录里运行WindowsApplication143.exe,从临时目录里的App.Config读值
      

  4.   

    把app.exe文件在工程里设置为Embedded资源不行吗?
      

  5.   

    就是如何写到程序里头,而不会有这个 .exe.config文件
      

  6.   

    既然做成服务  就应该能够被公开而不会出现安全问题!   哎,小弟就是觉得自己的web服务不安全啊