1

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

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();
        }
    }
4

0 回答 0