RadScheduler and AJAX-enabled Web Service

4 posts, 0 answers
  1. Paulo
    Paulo avatar
    31 posts
    Member since:
    Oct 2010

    Posted 16 Jun 2011 Link to this post

    Hello.

    I have built a very simple web page (Default.aspx) with the RadScheduler component:

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>
      
    <%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>
      
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:ScriptManager ID="ScriptManager1" runat="server">
            </asp:ScriptManager>
            <telerik:RadScheduler ID="RadScheduler1" runat="server">
                <WebServiceSettings Path="/App_Code/Service1.svc" ResourcePopulationMode="ServerSide" />
            </telerik:RadScheduler>
        </div>
        </form>
    </body>
    </html>

    and I have tried to integrate it with an AJAX-enabled web service (Service1.svc.cs):
    using System;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.ServiceModel.Activation;
    using System.ServiceModel.Web;
    using System.Data.Common;
    using Telerik.Web.UI;
    using System.Collections.Generic;
    using System.Data.SqlClient;
    using System.Configuration;
      
    namespace WebApplication1
    {
        [ServiceContract(Namespace = "")]
        [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
        [ServiceBehavior(IncludeExceptionDetailInFaults = true)]
      
        public class Service1
        {
            private WebServiceAppointmentController _controller;
            private MyProvider _provider;
      
            private MyProvider Provider
            {
                get
                {
                    if (_provider == null)
                    {
                        var connString = ConfigurationManager.ConnectionStrings["BossDB"].ConnectionString;
                        var factory = DbProviderFactories.GetFactory("System.Data.SqlClient");
                        _provider = new MyProvider() { ConnectionString = connString, DbFactory = factory, PersistChanges = true };
                    }
                    return _provider;
                }
            }
      
            private WebServiceAppointmentController Controller
            {
                get
                {
                    if (_controller == null)
                    {
                        _controller = new WebServiceAppointmentController(Provider);
                    }
                    return _controller;
                }
            }
      
            [OperationContract]
            public IEnumerable<AppointmentData> GetAppointments(SchedulerInfo schedulerInfo)
            {
                return Controller.GetAppointments(schedulerInfo);
            }
      
            [OperationContract]
            public IEnumerable<AppointmentData> InsertAppointment(SchedulerInfo schedulerInfo, AppointmentData appointmentData)
            {
                return Controller.InsertAppointment(schedulerInfo, appointmentData);
            }
      
            [OperationContract]
            public IEnumerable<AppointmentData> UpdateAppointment(SchedulerInfo schedulerInfo, AppointmentData appointmentData)
            {
                return Controller.UpdateAppointment(schedulerInfo, appointmentData);
            }
      
            [OperationContract]
            public IEnumerable<AppointmentData> DeleteAppointment(SchedulerInfo schedulerInfo, AppointmentData appointmentData,
                                                                   bool deleteSeries)
            {
                return Controller.DeleteAppointment(schedulerInfo, appointmentData, deleteSeries);
            }
      
            [OperationContract]
            public IEnumerable<AppointmentData> CreateRecurrenceException(SchedulerInfo schedulerInfo, AppointmentData recurrenceExceptionData)
            {
                return Controller.CreateRecurrenceException(schedulerInfo, recurrenceExceptionData);
            }
      
            [OperationContract]
            public IEnumerable<AppointmentData> RemoveRecurrenceExceptions(SchedulerInfo schedulerInfo, AppointmentData masterAppointmentData)
            {
                return Controller.RemoveRecurrenceExceptions(schedulerInfo, masterAppointmentData);
            }
      
        }
    }

    The web service references the data provider implemented in MyProvider.cs:
    using System;
    using System.Collections.Generic;
    using System.Data.Common;
    using System.Data.SqlClient;
    using System.Configuration;
    using System.Transactions;
    using Telerik.Web.UI;
      
    public class MyProvider : DbSchedulerProviderBase
    {
        private SqlConnection m_connection;
        private SqlCommand m_cmdReservationListSelect;
      
        public MyProvider()
        {
            m_connection = new SqlConnection(ConfigurationManager.ConnectionStrings["BossDB"].ConnectionString);
            m_cmdReservationListSelect = new SqlCommand("procReservationListSelect");
            m_cmdReservationListSelect.CommandType = System.Data.CommandType.StoredProcedure;
            m_cmdReservationListSelect.Connection = m_connection;
            m_cmdReservationListSelect.Parameters.Add(new SqlParameter("@ClubId", System.Data.SqlDbType.SmallInt));
            m_cmdReservationListSelect.Parameters.Add(new SqlParameter("@ResourceType", System.Data.SqlDbType.Char, 15));
            m_cmdReservationListSelect.Parameters.Add(new SqlParameter("@ReservationDate", System.Data.SqlDbType.Char, 10));
            m_cmdReservationListSelect.Parameters.Add(new SqlParameter("@ReservationType", System.Data.SqlDbType.Char, 1));
            m_cmdReservationListSelect.Parameters.Add(new SqlParameter("@MembershipNbr", System.Data.SqlDbType.Char, 10));
        }
      
        public override IEnumerable<Appointment> GetAppointments(ISchedulerInfo shedulerInfo)
        {
            Int16 clubId = 201;
            String resourceType = "PERS TRAINING";
            String reservationDate = "04/01/2011";
            String reservationType = "L";
            String membershipNbr = "";
            List<Appointment> appointments = new List<Appointment>();
      
            using (TransactionScope scope = new TransactionScope())
            {
                m_cmdReservationListSelect.Parameters["@ClubId"].Value = clubId;
                m_cmdReservationListSelect.Parameters["@ResourceType"].Value = resourceType;
                m_cmdReservationListSelect.Parameters["@ReservationDate"].Value = reservationDate;
                m_cmdReservationListSelect.Parameters["@ReservationType"].Value = reservationType;
                m_cmdReservationListSelect.Parameters["@MembershipNbr"].Value = membershipNbr;
      
                m_connection.Open();
      
                using (SqlDataReader reader = m_cmdReservationListSelect.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        int resource = reader.GetOrdinal("resource");
                        int reservation = reader.GetOrdinal("reservation");
                        int qoh = reader.GetOrdinal("qoh");
                        int limit = reader.GetOrdinal("limit");
                        int start_time = reader.GetOrdinal("start_time");
                        int res_units = reader.GetOrdinal("res_units");
                        int invtr_desc = reader.GetOrdinal("invtr_desc");
                        int trainer_cust_code = reader.GetOrdinal("trainer_cust_code");
                        int remaining_sessions = reader.GetOrdinal("remaining_sessions");
                        int recurring = reader.GetOrdinal("recurring");
      
                        while (reader.Read())
                        {
                            Appointment apt = new Appointment();
                            apt.ID = (!reader.IsDBNull(reservation) ? reader.GetInt32(reservation) : 0);
                            apt.Subject = (!reader.IsDBNull(invtr_desc) ? reader.GetString(invtr_desc) : "");
                            apt.Start = Convert.ToDateTime("04/01/2011 " + reader.GetString(start_time));
                            apt.End = Convert.ToDateTime("04/01/2011 " + reader.GetString(start_time)).AddHours(reader.GetInt16(res_units));
                            apt.RecurrenceRule = "";
                            apt.RecurrenceParentID = null;
                            appointments.Add(apt);
                        }
                    }
                }
                m_connection.Close();
                scope.Complete();
                return appointments;
            }
        }
      
        public override void Insert(ISchedulerInfo shedulerInfo, Appointment appointmentToInsert)
        {
            if (!PersistChanges)
            {
                return;
            }
        }
      
        public override void Update(ISchedulerInfo shedulerInfo, Appointment appointmentToUpdate)
        {
            if (!PersistChanges)
            {
                return;
            }
        }
      
        public override void Delete(ISchedulerInfo shedulerInfo, Appointment appointmentToDelete)
        {
            if (!PersistChanges)
            {
                return;
            }
        }
      
    }

    When I build the project in Visual Studio 2008, no errors are reported.
    However, at runtime, the following error is displayed:
    Server Error in '/' Application.
    --------------------------------------------------------------------------------
      
    Compilation Error 
    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 
      
    Compiler Error Message: CS0234: The type or namespace name 'Transactions' does not exist in the namespace 'System' (are you missing an assembly reference?)
      
    Source Error:
      
    Line 4:  using System.Data.SqlClient;
    Line 5:  using System.Configuration;
    Line 6:  using System.Transactions;
    Line 7:  using Telerik.Web.UI;
    Line 8:

    Line 6 is highlighted, indicating an error in statement "using System.Transactions;".

    In order to compile file MyProvider.cs, System.Transactions needs to be referenced not only in the source code, but also as part of the project, under "References".

    Is there another place where System.Transactions need to be referenced?

    I would appreciate whether someone could assist me in solving this problem.
    Thank you in advance.

    Paulo

  2. Veronica
    Admin
    Veronica avatar
    1213 posts

    Posted 17 Jun 2011 Link to this post

    Hi Paulo,

    Please make sure that you have the assembly System.Transactions in the References of your web application. If you don't have them you can add reference by right-clicking the .cproj file and select "Add new references ..." in the Solution Explorer. You can find this assembly in the .NET tab.

    If you still need some help - could you please open new support thread and attach your sample project as a .zip file. That way I can inspect it and help you.

    Thank you!

    Kind regards,
    Veronica Milcheva
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  3. Paulo
    Paulo avatar
    31 posts
    Member since:
    Oct 2010

    Posted 17 Jun 2011 Link to this post

    Hello, Veronica.

    Thank you for your reply.

    Yes, assembly System.Transactions is already listed under References.
    According to your request, I tried to open a new thread and attach the project as a zip file. However, the zip extension was not allowed. So, I will attach the project to thread http://www.telerik.com/account/support-tickets/view-ticket.aspx?threadid=407687.

    Thank you.
    Paulo

  4. Veronica
    Admin
    Veronica avatar
    1213 posts

    Posted 21 Jun 2011 Link to this post

    Hello Paulo,

    Thank you for the attached project in your other ticket. I've already answered you there.

    For those who follow the forum post - the solution is to add the System.Transactions assembly in the web.config file:
    <compilationdebug="false">
         <assemblies>
           <addassembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
           <addassembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
           <addassembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
           <addassembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
           <addassembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
           <addassembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
           <addassembly="System.Speech, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
           <addassembly="System.Transactions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
         </assemblies>
       </compilation>

    Greetings,
    Veronica Milcheva
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Back to Top