gguowang

SqlServer 、API编程、Asp.Net,Winform.......

  博客园 :: 首页 :: 联系 :: 订阅 订阅 :: 管理
  12 Posts :: 1 Stories :: 11 Comments :: 0 Trackbacks

公告

昵称:gguowang
园龄:4年9个月
粉丝:0
关注:0

搜索

 
 

常用链接

我的标签

最新评论

阅读排行榜

评论排行榜

推荐排行榜

2011年5月10日 #

问题1:  找不到域控制器

解决方法:

步骤1.这是可能是没有启用 高级TCP/IP设置上的 NetBIOS

步骤2.把Windows xp 系统的DNS 地址设为域服务器的IP地址;

步骤3.在命令提示符里运行 ipconfig/registerdns;

问题2:加入域时,找不到网络路径

步骤1. 检查TCP/IP Net BIOS 服务,使之处于启动状态;

步骤2. 检查本地连接属性里 Microsoft网络客户端,使之处于勾选状态

posted @ 2011-05-10 23:14 gguowang 阅读(52) 评论(0) 编辑

2011年3月2日 #

最近同事想要学习WCF,于是我从以前的项目中抽提了一个简单的例子。

该例子分为五个部分:

Host:服务器端,只是提供服务,用控制台程序实现的;

IService:服务契约,要随WCF客户端分发的一个类库,是WCF服务向外公布的服务接口的集合;

Service:服务实现,是服务的主体,驻留WCF服务器端,并通过接口向WCF客户端提供服务的类库;

Provider:服务代理,WCF客户端通过调用它来间接调用到WCF服务;

Client:客户端,WCF服务的使用者;

服务器端Host代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.Reflection;
using System.Configuration;
using System.ServiceModel.Configuration;
namespace Host
{
    class Program
    {
        static void Main(string[] args)
        {
            using (var host = new ServiceHost(typeof(Service.Caculate)))
            {
                host.Open();
                Console.WriteLine("Wcf Service is running !");
            }
            Console.Read();
        }
    }
}

服务器端的App.Config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
 <system.serviceModel>
  <services>
   <service name="Service.Caculate" behaviorConfiguration="IndexerServiceBehavior">
    <!--address="mex" 相对与baseAddress的网络地址-->
    <endpoint address="mex" binding="mexHttpBinding" contract="IService.ICaculate" />
    <host>
     <baseAddresses>
      <add baseAddress="http://localhost:8732/Wcf/Service/Caculate" />
     </baseAddresses>
    </host>
   </service>
  </services>
  <behaviors>
   <serviceBehaviors>
    <behavior name="IndexerServiceBehavior">
     <serviceMetadata httpGetEnabled="true" />
     <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
   </serviceBehaviors>
  </behaviors>
 </system.serviceModel>
</configuration>

服务契约IService,是一个类库项目,随客户端分发 :

(注:客户端可能分为多个应用程序,调用WCF服务的每个项目都要引用Provider.DLL和IService.DLL)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.ServiceModel;
namespace IService
{
    [ServiceContract]
    public interface ICaculate
    {
        [OperationContract]
        decimal Add(decimal x, decimal y);
    }
}

服务实现部分,是一个类库项目,驻留服务器端不随客户端分发,代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using IService;
using System.ServiceModel;
namespace Service
{
    /// <summary>
    ///Author   : Aricous
    ///Datetime : 20110301
    ///Function : Description
    /// </summary>
    public class Caculate : ICaculate
    {
        /// <summary>
        ///
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public decimal Add(decimal x, decimal y)
        {
            return (x + y);
        }
    }
}

供客户端调用的代理,这里称为服务提供者,是一个类库,随客户端分发:

(注:客户端可能分为多个应用程序,调用WCF服务的每个项目都要引用Provider.DLL和IService.DLL)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.ServiceModel;
namespace Provider
{
    /// <summary>
    ///Author   : Aricous
    ///Datetime : 20110301
    ///Function : Description
    /// </summary>
    public class Wcf
    {
        private static readonly Wcf instance = new Wcf();
        private Wcf() {}

        private static object mutex = new object();

        private static IService.ICaculate _CaculateService;
        /// <summary>
        ///
        /// </summary>
        public static IService.ICaculate CaculateService
        {
            get
            {
                if (_CaculateService == null)
                {
                    lock (mutex)
                    {
                        _CaculateService = new ChannelFactory<IService.ICaculate>("CaculateService").CreateChannel();
                    }
                }
                return _CaculateService;
            }
        }
    }
}

客户端调用WCF服务的例子:

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.ServiceModel;
namespace Client
{
    public partial class Mainform : Form
    {
        public Mainform()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            decimal x = Convert.ToDecimal(textBox1.Text.Trim());
            decimal y = Convert.ToDecimal(textBox2.Text.Trim());
            decimal z = Provider.Wcf.CaculateService.Add(x, y);
            textBox3.Text = z.ToString();
        }
    }
}

 

客户端配置文件App.Config内容如下:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
 <system.serviceModel>
  <client>
   <!--服务器端使用了相对网络地址,所以这里要在baseAddress(http://localhost:8732/Wcf/Service/Caculate)后加上相对地址:/mex-->
   <endpoint address="http://localhost:8732/Wcf/Service/Caculate/mex"
       binding="mexHttpBinding"
       contract="IService.ICaculate"
       name ="CaculateService" >
   </endpoint>
  </client>
 </system.serviceModel>
</configuration>

posted @ 2011-03-02 13:34 gguowang 阅读(659) 评论(5) 编辑

2010年7月13日 #

    由于以前已经写好了的函数需要DataRow 类型的数据,故需要把实体转换为DataRow。

实体是由工具生成的,复合主键被处理成ID,如下:

        /// <summary>
        /// 主键ID
        /// </summary>
        [DataMember]
        [CompositeKey()]
        public virtual DZ_ZJJCSJCompositeKey ID
        {
            get;
            set;
        }

复合主键的定义如下:

[DataContract]
    [Serializable()]
    public partial class DZ_ZJJCSJCompositeKey
    {
        private int _Qydm;
        private int _Gjdm;
        private int _Yqtdm;
        private int _Qkdm;
        private String _Jh;
        /// <summary>
        /// 企业代码
        /// </summary>
        [DataMember]
        [KeyProperty(Column = "QYDM", ColumnType = "Int32")]
        public virtual int QYDM
        {
            get { return this._Qydm; }
            set { this._Qydm = value; }
        }
        /// <summary>
        /// 国家代码
        /// </summary>
        [DataMember]
        [KeyProperty(Column = "GJDM", ColumnType = "Int32")]
        public virtual int GJDM
        {
            get { return this._Gjdm; }
            set { this._Gjdm = value; }
        }
        /// <summary>
        /// 油气田代码
        /// </summary>
        [DataMember]
        [KeyProperty(Column = "YQTDM", ColumnType = "Int32")]
        public virtual int YQTDM
        {
            get { return this._Yqtdm; }
            set { this._Yqtdm = value; }
        }
        /// <summary>
        /// 区块代码
        /// </summary>
        [DataMember]
        [KeyProperty(Column = "QKDM", ColumnType = "Int32")]
        public virtual int QKDM
        {
            get { return this._Qkdm; }
            set { this._Qkdm = value; }
        }
        /// <summary>
        /// 井号
        /// </summary>
        [DataMember]
        [KeyProperty(Column = "JH", ColumnType = "String")]
        public virtual String JH
        {
            get { return this._Jh; }
            set { this._Jh = value; }
        }
        public override string ToString()
        {
            return String.Join(":", new string[] {
                                this._Qydm.ToString(),this._Gjdm.ToString(),this._Yqtdm.ToString(),this._Qkdm.ToString(),this._Jh.ToString()
                                       });
        }
        public override bool Equals(object obj)
        {
            if ((obj == this))
            {
                return true;
            }
            if (((obj == null)
                        || (obj.GetType() != this.GetType())))
            {
                return false;
            }
            DZ_ZJJCSJCompositeKey test = ((DZ_ZJJCSJCompositeKey)(obj));
            return (((_Qydm == test._Qydm) || ((_Qydm != null) && _Qydm.Equals(test._Qydm))) && ((_Gjdm == test._Gjdm) || ((_Gjdm != null) && _Gjdm.Equals(test._Gjdm))) && ((_Yqtdm == test._Yqtdm) || ((_Yqtdm != null) && _Yqtdm.Equals(test._Yqtdm))) && ((_Qkdm == test._Qkdm) || ((_Qkdm != null) && _Qkdm.Equals(test._Qkdm))) && ((_Jh == test._Jh) || ((_Jh != null) && _Jh.Equals(test._Jh))));
        }
        public override int GetHashCode()
        {
            return XorHelper(_Jh.GetHashCode(), XorHelper(_Qkdm.GetHashCode(), XorHelper(_Yqtdm.GetHashCode(), XorHelper(_Gjdm.GetHashCode(), _Qydm.GetHashCode()))));
        }
        private int XorHelper(int left, int right)
        {
            return left ^ right;
        }
    }

这时用原来的反射方法已经不行了 !

研究了两个小时才得到如下的代码,故赶紧存一下,也给有类似需要的人分享一下:

   /// <summary>
        ///
        /// </summary>
        /// <param name="instance"></param>
        /// <returns></returns>
        public static DataRow ToDataRow(T instance)
        {
            if (instance == null)
                return null;
            Type type = typeof(T);
            DataTable table = new DataTable();
            PropertyInfo[] fields = type.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase);
            string temporary = string.Empty;
            Type temp = null;
            foreach (PropertyInfo field in fields)
            {
                temp = field.PropertyType;
                if (temp.FullName.StartsWith("System"))
                {
                    table.Columns.Add(field.Name);
                }
                else
                {
                    PropertyInfo[] pis = temp.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase);
                    foreach (PropertyInfo pi in pis)
                        table.Columns.Add(pi.Name);
                }
            }
            DataRow row = table.NewRow();
            foreach (PropertyInfo field in fields)
            {
                temp = field.PropertyType;
                if (temp.FullName.StartsWith("System"))
                {
                    row[field.Name] = field.GetValue(instance, null);
                }
                else
                {
                    PropertyInfo[] pis = temp.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase);
                    var vars = type.GetProperty(field.Name).GetValue(instance, null);
                    foreach (PropertyInfo pi in pis)
                    {
                        row[pi.Name] = pi.GetValue(vars, null);
                    }
                }
            }
            return row;
        }

posted @ 2010-07-13 17:54 gguowang 阅读(114) 评论(0) 编辑

2010年4月15日 #

1. session过期后如果在iframe里操作就会返回到Login.aspx,可是这个Login.aspx页面还在iframe里面如果再次登陆就会出现iframe嵌套的现象。

Google了好半天,终于得到了一些提示,原来这个问题我们可以这样来解决:

Response.Write(@"<script type='text/javascript'>window.top.location = '../Login.aspx'</script>");

原来这个问题可以很简单的解决 ~

2. iframe 自适应高度的问题:

这个问题需要借助Javascript脚本来解决,脚本代码如下:

/*************************************************************/

function resize()
    {
        var h=600;
        try
        {
            if(iframe && iframe.document && iframe.document.body)
            {
                var o = iframe.document.body;
                var h = o.scrollHeight + (typeof(o.clientTop)== 'number' ?o.clientTop * 2 : 0);
            }
        }
        catch(e)
        {
            var h=600;
            window.status=e.description;
        }
        if(h<600)
            {h=600;}
            document.getElementById('iframe').style.height=h+'px';
            return h+"px";
    }
    window.onresize=resize;

/*************************************************************/

调用该脚本的例子如下:

<iframe id="iframe" width="100%" src="User/List.aspx" onload="javascript:resize();" scrolling="no" frameborder="0" style="width: 100%;" height="22"></iframe>

欢迎大家斧正、拍砖 !

posted @ 2010-04-15 17:14 gguowang 阅读(179) 评论(1) 编辑

2009年4月16日 #

今天去给客户演示软件呢,突然发现程序启动不了了 !!! ???跳出来一个错误:

unable to start debugging on the web server.the web server could not find the requested resource

即:无法启动Web服务器。Web服务器无法找到请求的资源 !

嗡 !!!头大了 !!昨天刚弄好的程序怎么就不行了呢 ?后来在客户那里借到了上外网的网络(设置啊代理啊...就不说了)

立刻找解决的办法 !!敲入Google一搜,发现都是英文的一大片...倒 !!!搞了5分钟,还是没有搞定,得,先别将这个软件了 !

幸好还有另外一个部分给客户看,转移一下客户的注意力吧 !唉,一个上午都郁闷着,都没有记清楚客户到底讲了些什么 !!!

回到住处赶紧Google一下,半个小时终于搞明白了:这里 http://msdn.microsoft.com/zh-cn/library/ms165025.aspx有这么一段话:

如果安装了“URLScan”,在没有正确配置 urlscan.ini 配置文件的情况下可能会遇到此错误。有关更多信息,请参见 HOW TO: Configure URLScan to Protect ASP.NET Applications(如何:配置 URLScan 以保护 ASP.NET 应用程序)

得到了上面的启发,后来在这里:http://www.microsoft.com/taiwan/msdn/secmod/html/secmod114.mspx 终于找到了问题的答案!

urlscan默认的把调试谓词DEBUG给禁用掉了 !

于是恍然大悟,哦 !昨天安装MVC组件是,顺带把URLScan给安装上了,这一安装不要紧,它把调试给禁用了 !!!!

于是赶紧打开它的配置文件:C:\WINDOWS\system32\inetsrv\urlscan\urlscan.ini 来看并进行配置,

将DEBUG加入到 urlscan.ini文件中的 AllowVerbs  配置节中:

[AllowVerbs]
GET
HEAD
POST
DEBUG

同时,把 urlscan.ini文件中的 options 配置节中的:

AllowDotInPath项置为1 ,形如:

AllowDotInPath=1

好了,重新启动IIS,再次启动调试程序,一切都好了 !

唉,这样的错误啊,真不知道该怎么评价自己了 !晕啊 ....

 

posted @ 2009-04-16 13:38 gguowang 阅读(649) 评论(0) 编辑

2008年10月14日 #

摘要: 如下代码是添加一个虚拟节点以便让树的每一个节点显示为有子节点的形式,该树的节点是由Microsoft.Web.UI.WebControls.TreeNode扩展而来如下是扩展代码: /// <summary> /// Function:Extend the attributes of the TreeNode /// Refactor:Aricous /// Refactor date...阅读全文
posted @ 2008-10-14 14:08 gguowang 阅读(951) 评论(2) 编辑

2008年3月16日 #

摘要: 一个二维数组内的数据如下排列1a 1b null null null null2a null null null null null3a 3b null null null null4a null null null null null5a null null null null null6a null null null null null7a 7b null null null null如何用...阅读全文
posted @ 2008-03-16 15:37 gguowang 阅读(124) 评论(0) 编辑

2007年12月13日 #

摘要: 用.Net Remoting事件实现广播,可以用来让分布是应用程序加强同步阅读全文
posted @ 2007-12-13 22:15 gguowang 阅读(809) 评论(3) 编辑

2007年12月12日 #

摘要: C# winform用webClient上传下载文件阅读全文
posted @ 2007-12-12 13:38 gguowang 阅读(1305) 评论(0) 编辑

2007年12月11日 #

摘要: Winform下DataGrid多行删除之排错阅读全文
posted @ 2007-12-11 18:26 gguowang 阅读(210) 评论(0) 编辑