在另一个方法中使用一个方法的值

时间:2013-05-23 05:47:09

标签: c# web-services

我有一个网络服务,其中我有两种方法。第一种方法是用于向数据库插入数据,这种方法在类库应用程序中使用。第二种方法是在web应用程序中使用。使用activex在beb页面内调用类库应用程序。我想使用第一种方法插入带有classlibrary app值的网页值。我无法使用会话,因为新的不同会话正在为类库和网页创建。现在我正在使用静态。但是使用不同的用户静态将无法正常工作。请给我一个解决方案。

namespace WSSeac
{
/// <summary>
/// Descrizione di riepilogo per Service1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// Per consentire la chiamata di questo servizio Web dallo script utilizzando       ASP.NET    AJAX, rimuovere il commento dalla riga seguente. 
// [System.Web.Script.Services.ScriptService]
//   [OperationContract]
// [WebInvoke(Method = "GET", UriTemplate = "/GetMyObject?id={id}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]


public class Service1 : System.Web.Services.WebService
{

    static string temp="";
    [WebMethod(EnableSession = true)]
    public void GetImages(byte[] front, byte[] rear, byte[] frontTif, byte[] frontUV,  string MICR,string mid)
    {
        //Here you can save the images inside the DATABASE
        //return "OK";
        SqlConnection _sqlConnection = new SqlConnection();
        SqlCommand _sqlCommand = new SqlCommand();

        _sqlConnection.ConnectionString = ConfigurationManager.ConnectionStrings["elogicConnectionString"].ConnectionString;

        _sqlConnection.Open();

        _sqlCommand.Connection = _sqlConnection;
      // string aaa = HttpContext.Current.Session["aaaa"].ToString();
       string aaa = temp;

        string SQLString = "Insert into [elogic].[dbo].[seac](frontbw,backbw,frontgray,frontuv,micr,bank) values(@Content1,@Content2,@Content3,@Content4,@Content5,@Content6)";
      //  string SQLString = "Insert into [elogic].[dbo].[seac](frontbw,micr,bank) values(@Content1,@Content5,@Content6)";
        SqlParameter param1 = _sqlCommand.Parameters.Add("@Content1", SqlDbType.Image);
        param1.Value = front;
        SqlParameter param2 = _sqlCommand.Parameters.Add("@Content2", SqlDbType.Image);
        param2.Value = rear;
        SqlParameter param3 = _sqlCommand.Parameters.Add("@Content3", SqlDbType.Image);
        param3.Value = frontTif;
        SqlParameter param4 = _sqlCommand.Parameters.Add("@Content4", SqlDbType.Image);
        param4.Value = frontUV;
        SqlParameter param5 = _sqlCommand.Parameters.Add("@Content5", SqlDbType.Text);
        param5.Value = MICR;
        SqlParameter param6 = _sqlCommand.Parameters.Add("@Content6", SqlDbType.Text);
        param6.Value = aaa;
        _sqlCommand.CommandText = SQLString;
        _sqlCommand.ExecuteNonQuery();

        _sqlConnection.Close();


    }
    [WebMethod(EnableSession = true)]
    public void gettest(string bank)
    {
      temp = bank;
     //   Session["EmpName"] = bank;


    }

   [WebMethod(EnableSession = true)]//session returns null
    public string GetName()
    {
        if (Session["EmpName"] == null)
        {
            return "";
        }
        else
        {
            return Session["EmpName"].ToString();
        }
    }

0 个答案:

没有答案