HI!
I need that someone make a good example about how to use a wcf service to bind data to a area chart datasource....using a sql server database..
should i have this
Grafica.aspx code:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Grafica.aspx.cs" Inherits="CantidadDePagos2.Grafica" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<!DOCTYPE htmlL>
<html>
<head runat="server">
<title></title>
<script src="Scripts/jquery-1.7.2.min.js" type="text/javascript"></script>
<script src="Scripts/kendo/2012.2.710/kendo.all.min.js" type="text/javascript"></script>
<script src="Scripts/kendo/2012.2.710/kendo.dataviz.min.js" type="text/javascript"></script>
<link href="Content/kendo/2012.2.710/kendo.common.min.css" rel="stylesheet" type="text/css" />
<link href="Content/kendo/2012.2.710/kendo.default.min.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<div id="GAreaCPagos" runat="server">
</div>
<script type="text/jscript">
function graficaCPagos() {
$("#GAreaCPagos").kendoChart({
theme: $(document).data("kendoSkin") || "default",
dataSource: {
schema: {
data: "d",
model: {
fields: {
IDPAGOS: { type: "number" },
CANTPAGOS: { type: "number" }
}
}
},
transport: {
read: {
url: "ServicePagos.svc/ObtenerPagos"
contentType: "application/json; charset=utf-8"
type: "POST"
}
}
},
title: {
text: "Cantidad de Pagos",
color: "#848484"
},
legend: {
visible: true
},
seriesDefaults: {
type: "area"
},
series: [{ field: "CANTPAGOS"}],
valueAxis: {
labels: {
format: "{0}"
}
},
categoryAxis: {
field: "IDPAGOS"
},
tooltip: {
visible: true,
format: "{0} Id"
}
});
}
$(document).ready(function () { graficaCPagos(); })
</script>
</form>
</body>
</html>
ServicePagos.svc.cs code:
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
namespace CantidadDePagos2
{
public class ServicePagos : IServicePagos
{
private string strConnection = ConfigurationManager.ConnectionStrings["cas"].ToString();
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
public CompositeType GetDataUsingDataContract(CompositeType composite)
{
if (composite == null)
{
throw new ArgumentNullException("composite");
}
if (composite.BoolValue)
{
composite.StringValue += "Suffix";
}
return composite;
}
public List<IndiceMorosidad> ObtenerPagos()
{
List<IndiceMorosidad> pagos = new List<IndiceMorosidad>();
using (SqlConnection con = new SqlConnection(strConnection))
{
con.Open();
SqlCommand cmd = new SqlCommand("SELECT CodIndiceMorosidad, CantidadPagos FROM IndiceMorosidad", con);
SqlDataAdapter dta = new SqlDataAdapter(cmd);
DataTable dtresp = new DataTable();
dta.Fill(dtresp);
if (dtresp.Rows.Count > 0)
{
for (int i = 0; i < dtresp.Rows.Count; i++)
{
IndiceMorosidad infopago = new IndiceMorosidad();
infopago.IDPAGOS = int.Parse(dtresp.Rows[i]["CodIndiceMorosidad"].ToString());
infopago.CANTPAGOS = int.Parse(dtresp.Rows[i]["CantidadPagos"].ToString());
pagos.Add(infopago);
}
}
con.Close();
}
return pagos;
}
}
and i have the IServicePagos with this code:
namespace CantidadDePagos2
{
// NOTA: puede usar el comando "Rename" del menú "Refactorizar" para cambiar el nombre de interfaz "IServicePagos" en el código y en el archivo de configuración a la vez.
[ServiceContract(Name = "CantidadDePagos2")]
public interface IServicePagos
{
[OperationContract]
List<IndiceMorosidad> ObtenerPagos();
}
[DataContract]
public class IndiceMorosidad
{
int Id;
int CPagos;
[DataMember]
public int IDPAGOS
{
get { return Id; }
set { Id = value; }
}
[DataMember]
public int CANTPAGOS
{
get { return CPagos; }
set { CPagos = value; }
}
}
}
my web config is that:
<?xml version="1.0"?>
<!--
Para obtener más información sobre cómo configurar la aplicación de ASP.NET, visite
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<connectionStrings>
<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" />
<add name="cas" connectionString="Data Source=localhost;Initial Catalog=CASWEB_2012_;Persist Security Info=True;User ID=cas;Password=123" providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="System.Speech, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
<authentication mode="Forms">
<forms loginUrl="~/Account/Login.aspx" timeout="2880" />
</authentication>
<membership>
<providers>
<clear />
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
</providers>
</membership>
<profile>
<providers>
<clear />
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" />
</providers>
</profile>
<roleManager enabled="false">
<providers>
<clear />
<add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
<add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
</providers>
</roleManager>
<httpHandlers>
<add path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource" verb="*" validate="false" />
</httpHandlers>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<add name="Telerik_Web_UI_WebResource_axd" verb="*" preCondition="integratedMode" path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource" />
</handlers>
</system.webServer>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IServicePagos" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:56245/ServicePagos.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IServicePagos" contract="ServiceReference1.IServicePagos" name="BasicHttpBinding_IServicePagos" />
</client>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
</configuration>
someone that tell me how y make this area chart with the list of my wcfservice please
I need that someone make a good example about how to use a wcf service to bind data to a area chart datasource....using a sql server database..
should i have this
Grafica.aspx code:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Grafica.aspx.cs" Inherits="CantidadDePagos2.Grafica" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<!DOCTYPE htmlL>
<html>
<head runat="server">
<title></title>
<script src="Scripts/jquery-1.7.2.min.js" type="text/javascript"></script>
<script src="Scripts/kendo/2012.2.710/kendo.all.min.js" type="text/javascript"></script>
<script src="Scripts/kendo/2012.2.710/kendo.dataviz.min.js" type="text/javascript"></script>
<link href="Content/kendo/2012.2.710/kendo.common.min.css" rel="stylesheet" type="text/css" />
<link href="Content/kendo/2012.2.710/kendo.default.min.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<div id="GAreaCPagos" runat="server">
</div>
<script type="text/jscript">
function graficaCPagos() {
$("#GAreaCPagos").kendoChart({
theme: $(document).data("kendoSkin") || "default",
dataSource: {
schema: {
data: "d",
model: {
fields: {
IDPAGOS: { type: "number" },
CANTPAGOS: { type: "number" }
}
}
},
transport: {
read: {
url: "ServicePagos.svc/ObtenerPagos"
contentType: "application/json; charset=utf-8"
type: "POST"
}
}
},
title: {
text: "Cantidad de Pagos",
color: "#848484"
},
legend: {
visible: true
},
seriesDefaults: {
type: "area"
},
series: [{ field: "CANTPAGOS"}],
valueAxis: {
labels: {
format: "{0}"
}
},
categoryAxis: {
field: "IDPAGOS"
},
tooltip: {
visible: true,
format: "{0} Id"
}
});
}
$(document).ready(function () { graficaCPagos(); })
</script>
</form>
</body>
</html>
ServicePagos.svc.cs code:
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
namespace CantidadDePagos2
{
public class ServicePagos : IServicePagos
{
private string strConnection = ConfigurationManager.ConnectionStrings["cas"].ToString();
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
public CompositeType GetDataUsingDataContract(CompositeType composite)
{
if (composite == null)
{
throw new ArgumentNullException("composite");
}
if (composite.BoolValue)
{
composite.StringValue += "Suffix";
}
return composite;
}
public List<IndiceMorosidad> ObtenerPagos()
{
List<IndiceMorosidad> pagos = new List<IndiceMorosidad>();
using (SqlConnection con = new SqlConnection(strConnection))
{
con.Open();
SqlCommand cmd = new SqlCommand("SELECT CodIndiceMorosidad, CantidadPagos FROM IndiceMorosidad", con);
SqlDataAdapter dta = new SqlDataAdapter(cmd);
DataTable dtresp = new DataTable();
dta.Fill(dtresp);
if (dtresp.Rows.Count > 0)
{
for (int i = 0; i < dtresp.Rows.Count; i++)
{
IndiceMorosidad infopago = new IndiceMorosidad();
infopago.IDPAGOS = int.Parse(dtresp.Rows[i]["CodIndiceMorosidad"].ToString());
infopago.CANTPAGOS = int.Parse(dtresp.Rows[i]["CantidadPagos"].ToString());
pagos.Add(infopago);
}
}
con.Close();
}
return pagos;
}
}
}
and i have the IServicePagos with this code:
namespace CantidadDePagos2
{
// NOTA: puede usar el comando "Rename" del menú "Refactorizar" para cambiar el nombre de interfaz "IServicePagos" en el código y en el archivo de configuración a la vez.
[ServiceContract(Name = "CantidadDePagos2")]
public interface IServicePagos
{
[OperationContract]
List<IndiceMorosidad> ObtenerPagos();
}
[DataContract]
public class IndiceMorosidad
{
int Id;
int CPagos;
[DataMember]
public int IDPAGOS
{
get { return Id; }
set { Id = value; }
}
[DataMember]
public int CANTPAGOS
{
get { return CPagos; }
set { CPagos = value; }
}
}
}
my web config is that:
<?xml version="1.0"?>
<!--
Para obtener más información sobre cómo configurar la aplicación de ASP.NET, visite
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<connectionStrings>
<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" />
<add name="cas" connectionString="Data Source=localhost;Initial Catalog=CASWEB_2012_;Persist Security Info=True;User ID=cas;Password=123" providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="System.Speech, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
<authentication mode="Forms">
<forms loginUrl="~/Account/Login.aspx" timeout="2880" />
</authentication>
<membership>
<providers>
<clear />
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
</providers>
</membership>
<profile>
<providers>
<clear />
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" />
</providers>
</profile>
<roleManager enabled="false">
<providers>
<clear />
<add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
<add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
</providers>
</roleManager>
<httpHandlers>
<add path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource" verb="*" validate="false" />
</httpHandlers>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<add name="Telerik_Web_UI_WebResource_axd" verb="*" preCondition="integratedMode" path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource" />
</handlers>
</system.webServer>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IServicePagos" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:56245/ServicePagos.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IServicePagos" contract="ServiceReference1.IServicePagos" name="BasicHttpBinding_IServicePagos" />
</client>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
</configuration>
someone that tell me how y make this area chart with the list of my wcfservice please