新建一个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无法序列化,因为它没有无参数的构造函数,请问大家这该怎么办?
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无法序列化,因为它没有无参数的构造函数,请问大家这该怎么办?
PDAService.PDAWebService pdaService = new PDAService.PDAWebService();
WebServiceMethod me = new WebServiceMethod();
me.WebMethod(me.MethodA);
或者
me.WebMethod(me.MethodB);
我的目的是不用每次都对webservice中的方法都写事物了。请大家帮帮忙解决下,先谢谢了。