在WCF服务中调用过程时参数的数量或类型错误

时间:2017-03-30 16:25:44

标签: oracle web-services wcf visual-studio-2013

我有点困难。好吧,我有两种不同的解决方案(solution1有一个WebApplication Project; solution2有一个Website Project)。在这两个解决方案中,有一个WCF服务结构。我在两个服务中都有完全相同的代码(在各自的解决方案中)。我的代码编译得很好。从服务我简单地调用一个返回游标的过程。当我从WebApplication执行服务时,它工作得很好;当我从网站上做同样的事情时,我得到错误:“错误的数字或类型的参数”。它们都在同一个DB中调用相同的过程。我三重检查我的代码,在两个服务中是相同的。任何想法或建议?我的代码在以下两个解决方案中如下: Service.cs

public List<A1001310> SearchClient_A1001310()
    {
        DataTable dataTable = new DataTable();
        dataTable = DataManager.SearchClient();

        List<A1001310> list = new List<A1001310>();
        list = (from DataRow dr in dataTable.Rows
                select new A1001310()
                {
                    Id = Convert.ToInt32(dr["CLIENT_ID"]),
                    //ClientName = dr["NOM_CLIENTE"].ToString()
                }).ToList();
        return list;
    }

DataManager.cs

public static DataTable SearchClient()
    {
        try
        {
            using (OleDbCommand cmd = new OleDbCommand(packetName + ".select_A1001310"))
            {
                cmd.CommandType = CommandType.StoredProcedure;

                SqlManager sqlManager = new SqlManager();                    
                return sqlManager.GetDataTable(cmd);
            }
        }
        catch (Exception ex)
        {
            //TODO; Handle exception
        }
        return null;
    }

对DataTable的调用是:

public DataTable GetDataTable(OleDbCommand cmd)
    {
        using (DataSet ds = GetDataSet(cmd))
        {
            return ((ds != null && ds.Tables.Count > 0) ? ds.Tables[0] : null);
        }
    }

public DataSet GetDataSet(OleDbCommand cmd)
    {
        using (DataSet ds = new DataSet())
        {
            this.ConvertToNullBlankParameters(cmd);

            using (OleDbConnection conn = new OleDbConnection(cmd.Connection == null ? _dbConnection : cmd.Connection.ConnectionString))
            {
                cmd.Connection = conn;
                cmd.CommandTimeout = _connTimeout;

                conn.Open();
                //cmd.ExecuteScalar();

                using (OleDbDataAdapter da = new OleDbDataAdapter(cmd))
                    da.Fill(ds);
            }
            return ds;
        }
    }

程序如下:

    PROCEDURE select_A1001310(io_cursor OUT lcursor_data)
  AS
  BEGIN
    OPEN io_cursor FOR
    --
      SELECT client_id
        FROM a1001310
       WHERE status = 'A'
    --
  EXCEPTION
    WHEN OTHERS THEN
      IF io_cursor%ISOPEN THEN
        CLOSE io_cursor;
      END IF;
    --REVIRE: EXCEPTION HANDLER
  END select_A1001310;

1 个答案:

答案 0 :(得分:0)

因此,如果它可以帮助任何人,我通过指定过程中声明的OUT参数解决了我的问题。这导致我从Oledb变为OracleClient,如下所示:

public static DataTable SearchClient()
    {
        string connection = ConfigurationManager.ConnectionStrings["DBConnection_Oracle"].ToString();
        string procedure = packetName + ".p_search_client";

        OracleParameter[] parameters = new OracleParameter[1];
        parameters[0] = new OracleParameter("io_cursor", OracleType.Cursor, 4000, ParameterDirection.Output, true, 0, 0, "", DataRowVersion.Current, String.Empty);

        DataTable dt = new DataTable();
        dt = DataManager_Oracle.GetDataTable_(connection, procedure, parameters);
        return dt;
    }

似乎在网站环境中它不喜欢遗漏OUT参数;而在WebApplication上我没有指定它,它工作得很好......如果有人知道原因,请告诉我:))