新建一个Webservice中,我定义了一个委托:public delegate void WebDelegateMethod();
webservice中的一个方法:
        [WebMethod]
        public void WebMethod(WebDelegateMethod wsMethod)
        {
            ConnectionClass.conn = new SqlConnection(ConfigurationSettings.AppSettings["ConnectStr"]);
            ConnectionClass.cmd = new SqlCommand();
            SqlTransaction myTrans = ConnectionClass.conn.BeginTransaction();
            try
            {
                ConnectionClass.conn.Open();//打开连接                
                ConnectionClass.cmd.Transaction = myTrans;
                ConnectionClass.cmd.Connection = ConnectionClass.conn;
                wsMethod();
                myTrans.Commit();
            }
            catch
            {
                myTrans.Rollback();
            }
            finally
            {
                ConnectionClass.conn.Close();
            }
        } 
然后在客户端调用更新这个webservice引用的时候,就报错了,提示:webservice中WebDelegateMethod无法序列化,因为它没有无参数的构造函数,请问大家这该怎么办?

解决方案 »

  1.   

    客户端:
    PDAService.PDAWebService pdaService = new PDAService.PDAWebService();
    WebServiceMethod me = new WebServiceMethod();
    me.WebMethod(me.MethodA);
    或者
    me.WebMethod(me.MethodB);
    我的目的是不用每次都对webservice中的方法都写事物了。请大家帮帮忙解决下,先谢谢了。
      

  2.   

    你把 Webservice 里的链接数据库的操作拿出来,放到别的 dll中,然后再webservice 中调用这个dll提供的方法。看看。
      

  3.   

    WebMethod 调用引起的 , 你传进去的方法肯定有问题 
      

  4.   

    这没有什么可说的——web service是很基本的技术,之所以跨平台被各家开发平台厂商支持,就是因为它最低级,所以最通用。想要支持回调,为什么不从remoting开始学起呢?(当然,这也就放弃了web service的优势)