C#和WCF参考问题

时间:2012-07-06 14:59:56

标签: c# wcf

搞得一团糟,我确定这是一个愚蠢的。 解决方案:

项目1. Compania。 Linea.cs:只是具有不同构造函数的 Linea 类,现在就是它。

项目2. Bandeja。 Class.cs:在这里,我编写了使用 Linea 时我需要的所有方法。 (getLinea()是我将在下面的示例中向您展示的那个)

项目3. WCFWebService。 调用C#方法的WCF服务。

参考。

从Bandeja到Compania。

从WCFWebService到Compania。

从WCFWebService到Bandeja。

我在构建时遇到的唯一错误来自服务。

服务类

namespace WCFWebService
{
    [DataContract]
    public class WSBandeja : IWSBandeja
    {
        public Compania.Linea getLinea()
        {
            Compania.Linea linea = new Compania.Linea();
            return linea.

        }

    }
}

当我输入return.linea。我找不到Project Bandeja中class.cs中包含的方法getLinea(),只是参数。

任何建议都是最受欢迎的,因为我是C#和WebServices的新手。 感谢。

修改。 Compania项目 - Linea.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Compania
{
    public class Linea
    {
        public string ani { get; set; }
        public int teleprom { get; set; }
        public string actividad { get; set; }
        public DateTime fechaIngreso { get; set; }
        public string reclamo { get; set; }
        public string producto { get; set; }
        public string observacion { get; set; }
        public int tipoActividad { get; set; }
        public string tipoAveria { get; set; }
        public int reiteros { get; set; }
        public int call { get; set; }
        public bool trabajado { get; set; }
    }
}

Bandeja Project - Class.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
using System.Web;

namespace Bandeja
{
    public class Bandeja
    {
        public static string getNewConnection()
        {
            return ConfigurationManager.ConnectionStrings["BO"].ConnectionString;
        }

        public Compania.Linea getLinea()
        {
            var cLinea = new Compania.Linea();
            string connectionString = getNewConnection();
            SqlConnection conn = new SqlConnection(connectionString);
            using(conn)
            { 
                string variable = "GESTIONAR MANUALMENTE";
                var command = new SqlCommand("Bandeja_test");
                command.Connection = conn; 
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.Add(new SqlParameter("@linea", variable));
                conn.Open();
                SqlDataReader newReader = command.ExecuteReader();

                while (newReader.Read())
                {
                    cLinea = new Compania.Linea();
                    cLinea.ani = newReader["Línea"].ToString();
                    cLinea.fechaIngreso = Convert.ToDateTime(newReader["Fecha Ingreso"]);
                    cLinea.producto = newReader["Producto"].ToString();
                    cLinea.observacion = newReader["Observación"].ToString();
                }
            }

            return cLinea;
        }

    }

}

网络服务界面。

namespace WCFWebService
{
    [ServiceContract]
    public interface IWSBandeja
    {
        [OperationContract]
        Compania.Linea getLinea();

    }
}

2 个答案:

答案 0 :(得分:2)

看起来你正在实例化错误的类。试试这个。

[DataContract]
    public class WSBandeja : IWSBandeja
    {
        public Compania.Linea getLinea()
        {
            Bandeja.Bandeja bandeja = new Bandeja.Bandeja();
            return bandeja.getLinea();
        }
    }

答案 1 :(得分:1)

尝试

[ServiceContract]
    public class WSBandeja : IWSBandeja
    {
        [OperationContract]
        public Compania.Linea getLinea()
        {
            Compania.Linea linea = new Compania.Linea();
            return linea.
        }
    }

然后为复杂类型

定义[DataContract]
namespace Compania
{
[DataContract]
public class Linea
{

    [DataMember]
    //whatever properties you have
}

有关DataContracts和复杂类型的更多信息,请参阅this page