I have a list in C# with 4 items. This list is used to send a response in a web service and I need a specific order for the items, but I'm having a problem because, for some reason, the list changes the order when I fill it.
First, this is the class of the list
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
namespace Mvm.SATWeb.Domain
{
[Serializable, DataContract]
public class puntoDeAtencion
{
public puntoDeAtencion()
{
}
[DataMember]
public string codigoPuntoAtencion { get; set; }
[DataMember]
public decimal montoIngreso { get; set; }
[DataMember]
public decimal montoEgreso { get; set; }
[DataMember]
public decimal ingresoNeto { get; set; }
}
}
I use a SQL server query to fill the list with a dataset
List<puntoDeAtencion> valores = new List<puntoDeAtencion>();
DataSet ds;
Database baseDatos = DatabaseFactory.CreateDatabase();
DbCommand comandoConsulta = baseDatos.GetStoredProcCommand("USP_RiesgoLiqui");
comandoConsulta.CommandTimeout = 600000;
baseDatos.AddInParameter(comandoConsulta, "#pvstrIdAgencia", DbType.String, "-1");
baseDatos.AddInParameter(comandoConsulta, "#pvstrFechaInicial", DbType.String, FechaIni);
baseDatos.AddInParameter(comandoConsulta, "#pvstrFechaFinal", DbType.String, FechaFin);
comandoConsulta.CommandTimeout = 1000000;
// baseDatos.ExecuteDataSet();
ds = baseDatos.ExecuteDataSet(comandoConsulta);
if (ds.Tables.Count > 0)
{
for (int i = 0; i < ds.Tables[0].Rows.Count ; i++)
{
// valores.Add(s)
//valores.Add (new punptoDeAtencion(){}
valores.Add(new puntoDeAtencion() { codigoPuntoAtencion = Convert.ToString(ds.Tables[0].Rows[i]["Agencia"]), montoIngreso = Convert.ToDecimal(ds.Tables[0].Rows[i]["INGRESONETO"]), montoEgreso = Convert.ToDecimal(ds.Tables[0].Rows[i]["MONTOEGRESO"]), ingresoNeto = Convert.ToDecimal(0.00) });
// var list1 = (from p in ds.Tables[0].Rows[i] select p).ToList();
}
}
return valores.ToList<puntoDeAtencion>();
This is the response (Using SOAP UI, but when I debug show the same values in the response object)
<b:listaPuntosDeAtencion>
<b:puntoDeAtencion>
<b:codigoPuntoAtencion>001</b:codigoPuntoAtencion>
<b:ingresoNeto>0</b:ingresoNeto>
<b:montoEgreso>53266155.0000</b:montoEgreso>
<b:montoIngreso>138285187.0000</b:montoIngreso>
</b:puntoDeAtencion>
and this is how it should be
<listaPuntosDeAtencion>
<puntoDeAtencion>
<codigoPuntoAtencion>00654</codigoPuntoAtencion>
<montoIngreso>79000.0</montoIngreso>
<montoEgreso>30000.0</montoEgreso>
<ingresoNeto>0.0</ingresoNeto>
</puntoDeAtencion>
I want to order the list or the response, I don't know if LINQ works in this case.
You can order them by using Order on DataMember like this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
namespace Mvm.SATWeb.Domain
{
[Serializable, DataContract]
public class puntoDeAtencion
{
public puntoDeAtencion()
{
}
[DataMember(Order = 0)]
public string codigoPuntoAtencion { get; set; }
[DataMember(Order = 1)]
public decimal montoIngreso { get; set; }
[DataMember(Order = 2)]
public decimal montoEgreso { get; set; }
[DataMember(Order = 3)]
public decimal ingresoNeto { get; set; }
}
}
Documentation here: https://msdn.microsoft.com/en-us/library/ms729813.aspx
Related
I am having quite some trouble passing the Class type as paramater, since they represent tables and i only want to retrieve the result as a list
My function that takes the list is setDados(ds)
public void setDados(List<RP_EntityFrameWork_Tentativa.marcas> data)
{
gridControl1.DataSource = data;
gridView1.PopulateColumns();
Debug.WriteLine(data);
}
Which i have to before hand specify what class the list type is.
is there a way to be able to declare something along the lines of List<Class> or just pass a class as a parameter ?
all the classes i need to pass follow this same "Template"/Writing Style
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RP_EntityFrameWork_Tentativa
{
public class marcas
{
[Key]
[Required]
[StringLength(50)]
public string Marca { get; set; }
[StringLength(50)]
public string Descmarca { get; set; }
[StringLength(50)]
public string Nat { get; set; }
//ligação carros
public virtual ICollection<carros> carros{ get; set; }
}
}
i am currently using the following method
private void abreListaGeral(DevExpress.XtraEditors.ButtonEdit txt, List<marcas> ds, bool multiselect, int mode, int indexProcura)
{
this.Cursor = Cursors.WaitCursor;
String str = "";
frmQueryList lista = new frmQueryList();
lista.multiselect = multiselect;
lista.mode = mode;
lista.indexProcura = indexProcura;
lista.btnNovo.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
lista.btnNovo.Enabled = false;
lista.setDados(ds);
lista.ShowDialog();
str = lista.resultado2;
txt.Text = lista.resultado;
lista.frmIniciado = false;
lista.Close();
this.Cursor = Cursors.Default;
}
Which works but i have to create a new method for every Class i need to use this way create a bunch of overrites and useless code that could surely be optimized
What i am looking for is to have abreListaGeral() take as arguments such as List<marcas> List<carros> List<etc> without having to previously specify it
Sorry for the somewhat basic question, but what can I say. I can't figure it out. The problem is that there's a foreach loop that's supposed to iterate through the rows (sections) and while it works for the first section, the second time through the loop it doesn't seem to read the second section. The same data is stored in version. BTW, the way the method is called I would be passing in ProductName as a parameter (There will be multiple products represented here and also a version number (e.g. v2.0.0) that I'll need to filter the results for too.
So I have an XML file that looks like this:
<Products>
<ProductName1>
<v2.0.0>
<GUID>"{B5ECEC43-5406-4E4D-96D9-456823100313}"</GUID>
<VersionNameToUninstall>"2.0.0 - 2.0.2"</VersionNameToUninstall>
<UninstallResponseFile>"GVQC-Client-2.0.0-Uninst.iss"</UninstallResponseFile>
</v2.0.0>
<v2.0.3>
<GUID>"{1D6C02D7-8E87-43BE-8AB2-1FF0E5ACD410}"</GUID>
<VersionNameToUninstall>"2.0.3"</VersionNameToUninstall>
<UninstallResponseFile>"GVQC-Client-2.0.3-Uninst.iss"</UninstallResponseFile>
</v2.0.3>
</ProductName1>
<ProductName2>
<v3.0.0>
<GUID>"{ABCDEC43-5406-4E4D-96D9-456823101234}"</GUID>
<VersionNameToUninstall>"2.2.0 - 2.2.2"</VersionNameToUninstall>
<UninstallResponseFile>"GVQC-Client-2.2.0-Uninst.iss"</UninstallResponseFile>
</v3.0.0>
<v4.0.0>
<GUID>"{5D6C02D7-8E87-43BE-8AB2-1FF0E5ACD589}"</GUID>
<VersionNameToUninstall>"4.0.0"</VersionNameToUninstall>
<UninstallResponseFile>"GVQC-Client-4.0.0-Uninst.iss"</UninstallResponseFile>
</v4.0.0>
</ProductName2>
</Products>
There will only be 10 or so versions (e.g. v2.x.x) so there's not a lot of data here. So I created a multidimensional (nested) class/struct to hold the data and when I try my code to read the data it's not working.
Here are the classes/stucts (I've tried both and neither works) that I'm trying to populate:
public class TopLevelObject
{
public string Version { get; set; }
public RowLevelObject Row {get;set;}
}
public struct RowLevelObject
{
public string Guid { get; set; }
public string VersionName { get; set; }
public string UninstallFileName { get; set; }
}
So here's my code. Please just ignore the Stream - that's so I can embed this XML file in the .exe and not have it be a separate file:
public static List<TopLevelObject> GetGUIDSFromFile(string GUIDKey)
List<InstallScriptMSIXMLTopLevelObject> installScriptMSIXMLTopLevelObjectList = new List<InstallScriptMSIXMLTopLevelObject>();
Stream GUIDXmlFileStream = typeof(PGCommonCA).Assembly.GetManifestResourceStream("PGCommonCA.ProductGUIDs.xml");
XElement xElement = XElement.Load(GUIDXmlFileStream);
var versions = xElement.Elements(GUIDKey).Descendants();
foreach (var version in versions)
{
TopLevelObject topLevelObject = new TopLevelObject();
RowLevelObject rowLevelObject = new RowLevelObject();
TopLevelObject.Version = version.Name.LocalName;
RowLevelObject.Guid = version.Element("GUID").Value;
RowLevelObject.VersionName = version.Element("VersionNameToUninstall").Value;
RowLevelObject.UninstallFileName = version.Element("UninstallResponseFile").Value;
TopLevelObjectList.Add(topLevelObject);
}
return TopLevelObjectList;
}
I know there are many ways to read XML and my choice doesn't work so I'm looking for another simple solution.
The following works :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
const string FILENAME = #"c:\temp\test.xml";
static void Main(string[] args)
{
XDocument doc = XDocument.Load(FILENAME);
XElement productName = doc.Root;
List<TopLevelObject> top = productName.Elements().Select(x => new TopLevelObject() {
Version = x.Name.LocalName,
Row = new RowLevelObject() {
Guid = (string)x.Element("GUID"),
VersionName = (string)x.Element("VersionNameToUninstall"),
UninstallFileName = (string)x.Element("UninstallResponseFile")
}
}).ToList();
}
}
public class TopLevelObject
{
public string Version { get; set; }
public RowLevelObject Row { get; set; }
}
public struct RowLevelObject
{
public string Guid { get; set; }
public string VersionName { get; set; }
public string UninstallFileName { get; set; }
}
}
I figured it out (many thanks to jdweng!!). Here's the final solution based on the revised XML at the top:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
const string FILENAME = #"c:\temp\test.xml";
static TopLevelObject GetInfo(string xmlKey)
{
XDocument doc = XDocument.Load(FILENAME);
XElement productName = doc.Root;
List<TopLevelObject> top = productName.Descendants(xmlKey).Elements().Select(x => new TopLevelObject() {
Version = x.Name.LocalName,
Row = new RowLevelObject() {
Guid = (string)x.Element("GUID"),
VersionName = (string)x.Element("VersionNameToUninstall"),
UninstallFileName = (string)x.Element("UninstallResponseFile")
}
}).ToList();
}
}
public class TopLevelObject
{
public string Version { get; set; }
public RowLevelObject Row { get; set; }
}
public struct RowLevelObject
{
public string Guid { get; set; }
public string VersionName { get; set; }
public string UninstallFileName { get; set; }
}
}
RESOLVED: I stopped treating the string like an array and instead added a line-feed delimiter to the connection manager, so that each row was treated like a new line. This has resolved the issue and eliminated the need to handle this via a C# script.
I've built an SSIS package that uses a C# script task to deserialize JSON strings and insert them into a table.
I've got this working with a prototype JSON string:
{"name":"Test 1","code":"398057008","table":"SNOMEDCT","addedby":"morgan.baxter","dateadded":1544523489235,"qualifier":[{"name":"Qualifier","value":"Confirmed Diagnosis","code":"410605003","prefix":"[C] "}],"prefix":"[C] "}
But when I try to add a second item to the JSON string I receive an error:
[{"name":"Test 2","code":"398057008","table":"SNOMEDCT","addedby":"morgan.baxter","dateadded":1544523489235,"qualifier":[{"name":"Qualifier","value":"Confirmed Diagnosis","code":"410605003","prefix":"[C] "}],"prefix":"[C] "},{"name":"Test 2","code":"44255352","table":"SNOMEDCT","addedby":"morgan.baxter","dateadded":1544523489235,"qualifier":[{"name":"Qualifier","value":"Confirmed Diagnosis","code":"53252355","prefix":"[C] "}],"prefix":"[C] "}]
Error:
Type 'SC_8aae662509ae4bab8491323924579173.Diagnosis' is not supported
for deserialization of an array.
From what I can understand, this is simply saying that my 'Parser' essentially cannot support an array of JSON fields in a string.
Here is my main code block:
#region Namespaces
using System;
using System.Data;
using System.Collections.Generic;
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
using Microsoft.SqlServer.Dts.Runtime.Wrapper;
using System.Web.Script.Serialization;
using Microsoft.SqlServer.Dts.Pipeline;
namespace SC_8aae662509ae4bab8491323924579173
#endregion
{
[Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
public class ScriptMain : UserComponent
{
///<param name="Row">The row that is currently passing through the component</param>;
public override void Input0_ProcessInputRow(Input0Buffer Row)
{
JavaScriptSerializer js = new JavaScriptSerializer();
// Give the input column a variable to make it easier to reference.
BlobColumn combinedColumn = Row.Column0;
// Convert from blob to string
string reviewConverted = System.Text.Encoding.ASCII.GetString(combinedColumn.GetBlobData(0, Convert.ToInt32(combinedColumn.Length)));
Diagnosis diagnosis = new Diagnosis();
// Deserialize the string
diagnosis = js.Deserialize<Diagnosis>(reviewConverted);
// Assign values to output columns
Row.name = diagnosis.name;
Row.code = diagnosis.code;
Row.table = diagnosis.table;
Row.addedby = diagnosis.addedby;
Row.dateadded = diagnosis.dateadded;
Row.qualifierName = diagnosis.Qualifier[0].name;
Row.qualifierValue = diagnosis.Qualifier[0].value;
Row.qualifierCode = diagnosis.Qualifier[0].code;
Row.qualifierPrefix = diagnosis.Qualifier[0].prefix;
if (diagnosis.Qualifier.Length == 2)
{
Row.lrName = diagnosis.Qualifier[1].name;
Row.lrValue = diagnosis.Qualifier[1].value;
Row.lrCode = diagnosis.Qualifier[1].code;
Row.lrSuffix = diagnosis.Qualifier[1].prefix;
}
Row.jsonString = reviewConverted;
Row.prefix = diagnosis.prefix;
Row.suffix = diagnosis.suffix;
}
}
}
Qualifier class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SC_8aae662509ae4bab8491323924579173
{
class qualifier
{
public string name { get; set; }
public string value { get; set; }
public string code { get; set; }
public string prefix { get; set; }
}
}
Diagnosis class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SC_8aae662509ae4bab8491323924579173
{
class Diagnosis
{
public string name { get; set; }
public string code { get; set; }
public string table { get; set; }
public string addedby { get; set; }
public string dateadded { get; set; }
public qualifier[] Qualifier { get; set; }
public string prefix { get; set; }
public string suffix { get; set; }
public string jsonString { get; set; }
}
}
I've tried to cater for more than one diagnosis with an array and my if function, but to no avail. Any ideas? Many thanks.
You say, that you pass array instead of an object in json. So why do you keep trying to deserialize into Diagnosis object?
You should really use Collection with your type Diagnosis here:
// Deserialize the string
var diagnosisCollection = js.Deserialize<ICollection<Diagnosis>>(reviewConverted);
instead of old
// Deserialize the string
diagnosis = js.Deserialize<Diagnosis>(reviewConverted);
And then assign values for you output columns, using foreach
foreach (var diagnosis in diagnosisCollection ) {
// do stuff with your buffer here
}
SSIS script can be a wierd environment. And you're right to avoid using a 3rd party JSON parser here. But somewhere you've got the type definitions messed up.
I often find it useful to write, test and troubleshoot code in a console app before integrating it into an SSIS script component/task. EG
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp14
{
class Program
{
class qualifier
{
public string name { get; set; }
public string value { get; set; }
public string code { get; set; }
public string prefix { get; set; }
}
class Diagnosis
{
public string name { get; set; }
public string code { get; set; }
public string table { get; set; }
public string addedby { get; set; }
public string dateadded { get; set; }
public qualifier[] Qualifier { get; set; }
public string prefix { get; set; }
public string suffix { get; set; }
public string jsonString { get; set; }
}
static void Main(string[] args)
{
var json = #"
[
{
""name"": ""Test 2"",
""code"": ""398057008"",
""table"": ""SNOMEDCT"",
""addedby"": ""morgan.baxter"",
""dateadded"": 1544523489235,
""qualifier"": [
{
""name"": ""Qualifier"",
""value"": ""Confirmed Diagnosis"",
""code"": ""410605003"",
""prefix"": ""[C] ""
}
],
""prefix"": ""[C] ""
},
{
""name"": ""Test 2"",
""code"": ""44255352"",
""table"": ""SNOMEDCT"",
""addedby"": ""morgan.baxter"",
""dateadded"": 1544523489235,
""qualifier"": [
{
""name"": ""Qualifier"",
""value"": ""Confirmed Diagnosis"",
""code"": ""53252355"",
""prefix"": ""[C] ""
}
],
""prefix"": ""[C] ""
}
]
";
System.Web.Script.Serialization.JavaScriptSerializer js = new System.Web.Script.Serialization.JavaScriptSerializer();
// Deserialize the string
var diagnoses = js.Deserialize<Diagnosis[]>(json);
Console.WriteLine("Complete");
Console.ReadKey();
}
}
}
Here's my issue : I need to get a list of resources from a web services, and deserialize it into object. But it doesn't work, despite the facts my code worked with another xml file. So I can't figure why it doesn't work, and I'm stuck with that !
Here's the XML :
<ResourceDataSet xmlns="http://schemas.microsoft.com/office/project/server/webservices/ResourceDataSet/">
<Resources>
<RES_UID>blabla</RES_UID>
<RES_NAME>blabla</RES_NAME>
<RES_CODE>blabla</RES_CODE>
<RES_GROUP>blabla</RES_GROUP>
<RES_COST_CENTER>blabla</RES_COST_CENTER>
</Resources>
<Resources>
<RES_UID>blabla</RES_UID>
<RES_NAME>blabla</RES_NAME>
<RES_CODE>blabla</RES_CODE>
<RES_GROUP>blabla</RES_GROUP>
<RES_COST_CENTER>blabla</RES_COST_CENTER>
</Resources>
<Resources>
<RES_UID>blabla</RES_UID>
<RES_NAME>blabla</RES_NAME>
<RES_CODE>blabla</RES_CODE>
<RES_GROUP>blabla</RES_GROUP>
<RES_COST_CENTER>blabla</RES_COST_CENTER>
</Resources>
</ResourceDataSet>
The class I want to deserialize into :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using System.Threading.Tasks;
using System.Collections;
namespace TestWPF
{
[Serializable()]
public class Employee
{
[System.Xml.Serialization.XmlElement("RES_UID")]
public int RES_UID { get; set; }
[System.Xml.Serialization.XmlElement("RES_NAME")]
public String RES_NAME { get; set; }
[System.Xml.Serialization.XmlElement("RES_CODE")]
public String RES_CODE { get; set; }
[System.Xml.Serialization.XmlElement("RES_GROUP")]
public String RES_GROUP { get; set; }
[System.Xml.Serialization.XmlElement("RES_COST_CENTER")]
public String RES_COST_CENTER { get; set; }
public Employee()
{ }
public Employee(int r_id, String res_name, String res_code, String res_group, String res_cost_center)
{
this.RES_UID = r_id;
this.RES_NAME = res_name;
this.RES_CODE = res_code;
this.RES_GROUP = res_group;
this.RES_COST_CENTER = res_cost_center;
}
}
[Serializable()]
[System.Xml.Serialization.XmlRoot("ResourceDataSet")]
public class EmployeeList //: IEnumerator, IEnumerable
{
public EmployeeList() {Items = new List<Employee>();}
[XmlArray("ResourceDataSet")]
[XmlArrayItem("Resources")]
public List<Employee> Items {get;set;}
}
}
And the code I use to deserialize :
EmployeeList lstEmployee = null;
XmlSerializer xs = new XmlSerializer(typeof(ServersList));
StreamReader sr = new StreamReader("testEmployee.xml");
lstEmployee = (EmployeeList)serializer.Deserialize(sr);
reader.Close();
for (int i = 0; i < lstEmployee.Items.Count(); i++)
{
MessageBox.Show(lstEmployee.Items[i].RES_NAME);
}
And when I try to launch I receive this error message :
Firstly your xml file is invalid - RES_UID is expecting an int, so even when you get your serialization working you'll run into that problem.
You're also not taking into account the namespace. The following class works:
[Serializable()]
public class Employee
{
[System.Xml.Serialization.XmlElement("RES_UID")]
public int RES_UID { get; set; }
[System.Xml.Serialization.XmlElement("RES_NAME")]
public String RES_NAME { get; set; }
[System.Xml.Serialization.XmlElement("RES_CODE")]
public String RES_CODE { get; set; }
[System.Xml.Serialization.XmlElement("RES_GROUP")]
public String RES_GROUP { get; set; }
[System.Xml.Serialization.XmlElement("RES_COST_CENTER")]
public String RES_COST_CENTER { get; set; }
public Employee()
{ }
public Employee(int r_id, String res_name, String res_code, String res_group, String res_cost_center)
{
this.RES_UID = r_id;
this.RES_NAME = res_name;
this.RES_CODE = res_code;
this.RES_GROUP = res_group;
this.RES_COST_CENTER = res_cost_center;
}
}
[Serializable()]
[System.Xml.Serialization.XmlRoot("ResourceDataSet", Namespace = "http://schemas.microsoft.com/office/project/server/webservices/ResourceDataSet/")]
public class EmployeeList //: IEnumerator, IEnumerable
{
public EmployeeList() {Items = new List<Employee>();}
[XmlElement("Resources", Type = typeof(Employee))]
public List<Employee> Items {get;set;}
}
}
and your calling code with the typos fixed:
EmployeeList lstEmployee = null;
XmlSerializer xs = new XmlSerializer(typeof(EmployeeList));
StreamReader sr = new StreamReader("testEmployee.xml");
lstEmployee = (EmployeeList)xs.Deserialize(sr);
sr.Close();
for (int i = 0; i < lstEmployee.Items.Count(); i++)
{
MessageBox.Show(lstEmployee.Items[i].RES_NAME);
}
Remember to fix your xml to be ints otherwise it still won't work
You need to either decorate your root entity with the XmlRoot attribute or Or specify the root attribute when de serializing at runtime.
Here is a thread about this issue
https://stackoverflow.com/a/1557145/1305119
Got all mixed up and I'm sure it's a silly one.
Solution:
Project 1. Compania.
Linea.cs: Just the Linea class with different constructors and that's it for now.
Project 2. Bandeja.
Class.cs: Here I wrote all the methods I'll be needing when working with Linea. (getLinea() is the one I'll be showing you in the example below)
Project 3. WCFWebService.
A WCF service calling the C# methods.
References.
from Bandeja to Compania.
from WCFWebService to Compania.
from WCFWebService to Bandeja.
The only one error I get while building comes from the service.
Service Class
namespace WCFWebService
{
[DataContract]
public class WSBandeja : IWSBandeja
{
public Compania.Linea getLinea()
{
Compania.Linea linea = new Compania.Linea();
return linea.
}
}
}
When I enter return.linea. I can't find the method getLinea() contained in class.cs inside Project Bandeja, just the parameters.
Any suggestion is most welcome since I'm new to C# and WebServices.
Thanks.
EDIT.
Compania Project - 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;
}
}
}
The Web Service Interface.
namespace WCFWebService
{
[ServiceContract]
public interface IWSBandeja
{
[OperationContract]
Compania.Linea getLinea();
}
}
Looks like you are instantiating the wrong class. Try this.
[DataContract]
public class WSBandeja : IWSBandeja
{
public Compania.Linea getLinea()
{
Bandeja.Bandeja bandeja = new Bandeja.Bandeja();
return bandeja.getLinea();
}
}
Try
[ServiceContract]
public class WSBandeja : IWSBandeja
{
[OperationContract]
public Compania.Linea getLinea()
{
Compania.Linea linea = new Compania.Linea();
return linea.
}
}
And then define a [DataContract] for the complex type
namespace Compania
{
[DataContract]
public class Linea
{
[DataMember]
//whatever properties you have
}
See this page for more info on DataContracts and complex types