I'm trying to get a RADScheduler project switched over from using calls directly to a SQL Server database, to working with a WCF service. I took the example provided and modified it to work in our situation. But, I'm getting a webexception:
The remote server returned an error: (415) Cannot process the message because the content type 'application/json; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'.. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Net.WebException: The remote server returned an error: (415) Cannot process the message because the content type 'application/json; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'..
Source Error:
Stack Trace:
This is my IAppointmentsWCF.vb code:
This is my AppointmentsWCF.svc.vb code:
This is the Web.config file:
The application with the RADScheduler is as follows.
This is the AppointmentDisplay.ascx code:
This is the codebehind:
I have been hacking away at this for almost a week and just can't get his to work! Anyone here that can help with this?
Thanks.
The remote server returned an error: (415) Cannot process the message because the content type 'application/json; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'.. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Net.WebException: The remote server returned an error: (415) Cannot process the message because the content type 'application/json; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'..
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. |
Stack Trace:
|
This is my IAppointmentsWCF.vb code:
Imports System.Collections.GenericImports System.ServiceModelImports System.ServiceModel.ActivationImports System.WebImports Telerik.Web.UIImports System.ConfigurationImports System.Data.Common<ServiceContract([Namespace]:="MedSpaOnline.com")> _<AspNetCompatibilityRequirements(RequirementsMode:=AspNetCompatibilityRequirementsMode.Allowed)> _<ServiceBehavior(IncludeExceptionDetailInFaults:=True)> _Public Class SchedulerWcfService Private _controller As WebServiceAppointmentController Private _provider As AppointmentsProvider Private ReadOnly Property Provider() As AppointmentsProvider Get If _provider Is Nothing Then Dim crypto As Encryption.Crypto = New Encryption.Crypto("Suncoast") Dim connString = crypto.Decrypt(ConfigurationManager.ConnectionStrings("POS").ConnectionString) Dim factory = DbProviderFactories.GetFactory("System.Data.SqlClient") _provider = New AppointmentsProvider() _provider.ConnectionString = connString _provider.DbFactory = factory _provider.PersistChanges = True End If Return _provider End Get End Property ''' <summary> ''' The WebServiceAppointmentController class is used as a facade to the SchedulerProvider. ''' </summary> Private ReadOnly Property Controller() As WebServiceAppointmentController Get If _controller Is Nothing Then _controller = New WebServiceAppointmentController(Provider) End If Return _controller End Get End Property <OperationContract> _ <WebInvoke(BodyStyle:=WebMessageBodyStyle.Wrapped)> _ Public Function GetAppointments(schedulerInfo As MySchedulerInfo) As IEnumerable(Of AppointmentData) Return Controller.GetAppointments(schedulerInfo) End Function <OperationContract> _ <WebInvoke(BodyStyle:=WebMessageBodyStyle.Wrapped)> _ Public Function InsertAppointment(schedulerInfo As MySchedulerInfo, appointmentData As AppointmentData) As IEnumerable(Of AppointmentData) Return Controller.InsertAppointment(schedulerInfo, appointmentData) End Function <OperationContract> _ <WebInvoke(BodyStyle:=WebMessageBodyStyle.Wrapped)> _ Public Function UpdateAppointment(schedulerInfo As MySchedulerInfo, appointmentData As AppointmentData) As IEnumerable(Of AppointmentData) Return Controller.UpdateAppointment(schedulerInfo, appointmentData) End Function <OperationContract> _ <WebInvoke(BodyStyle:=WebMessageBodyStyle.Wrapped)> _ Public Function CreateRecurrenceException(schedulerInfo As MySchedulerInfo, recurrenceExceptionData As AppointmentData) As IEnumerable(Of AppointmentData) Return Controller.CreateRecurrenceException(schedulerInfo, recurrenceExceptionData) End Function <OperationContract> _ <WebInvoke(BodyStyle:=WebMessageBodyStyle.Wrapped)> _ Public Function RemoveRecurrenceExceptions(schedulerInfo As MySchedulerInfo, masterAppointmentData As AppointmentData) As IEnumerable(Of AppointmentData) Return Controller.RemoveRecurrenceExceptions(schedulerInfo, masterAppointmentData) End Function <OperationContract> _ <WebInvoke(BodyStyle:=WebMessageBodyStyle.Wrapped)> _ Public Function DeleteAppointment(schedulerInfo As MySchedulerInfo, appointmentData As AppointmentData, deleteSeries As Boolean) As IEnumerable(Of AppointmentData) Return Controller.DeleteAppointment(schedulerInfo, appointmentData, deleteSeries) End Function <OperationContract> _ <WebInvoke(BodyStyle:=WebMessageBodyStyle.Wrapped)> _ Public Function GetResources(schedulerInfo As MySchedulerInfo) As IEnumerable(Of ResourceData) Return Controller.GetResources(schedulerInfo) End FunctionEnd ClassThis is my AppointmentsWCF.svc.vb code:
cmd.Connection = conn cmd.Parameters.Add(CreateParameter("@StoreID", StoreID)) cmd.CommandText = "CustomerAppointmentSelect" cmd.CommandType = CommandType.StoredProcedure Using reader As DbDataReader = cmd.ExecuteReader() While reader.Read() Dim res As New Resource() res.Type = "customer" res.Key = reader("CustomerID") res.Text = Convert.ToString(reader("CustomerName")) resources.Add(res) End While End Using End Using Return resources End Function 'Private Sub FillClassCustomers(appointment As Appointment, cmd As DbCommand, classId As Object) ' For Each customer As Resource In appointment.Resources.GetResourcesByType("customer") ' cmd.Parameters.Clear() ' cmd.Parameters.Add(CreateParameter("@ClassID", classId)) ' cmd.Parameters.Add(CreateParameter("@customerID", customer.Key)) ' cmd.CommandText = "INSERT INTO [DbProvider_ClassCustomers] ([ClassID], [customerID]) VALUES (@ClassID, @customerID)" ' cmd.ExecuteNonQuery() ' Next 'End Sub 'Private Sub ClearClassCustomers(classId As Object, cmd As DbCommand) ' cmd.Parameters.Clear() ' cmd.Parameters.Add(CreateParameter("@ClassID", classId)) ' cmd.CommandText = "DELETE FROM [DbProvider_ClassCustomers] WHERE [ClassID] = @ClassID" ' cmd.ExecuteNonQuery() 'End Sub Private Sub PopulateAppointmentParameters(cmd As DbCommand, apt As Appointment, ByVal Action As String) If Action.Equals("UPDATE") Then cmd.Parameters.Add(CreateParameter("@ID", apt.ID)) End If cmd.Parameters.Add(CreateParameter("@StoreID", StoreID)) cmd.Parameters.Add(CreateParameter("@Subject", apt.Subject)) cmd.Parameters.Add(CreateParameter("@Start", apt.Start)) cmd.Parameters.Add(CreateParameter("@End", apt.[End])) Dim customer As Resource = apt.Resources.GetResourceByType("customer") Dim customerId As Object = Nothing If customer IsNot Nothing Then customerId = customer.Key End If cmd.Parameters.Add(CreateParameter("@CustomerID", customerId)) Dim employee As Resource = apt.Resources.GetResourceByType("employee") Dim employeeId As Object = Nothing If employee IsNot Nothing Then employeeId = employee.Key End If cmd.Parameters.Add(CreateParameter("@EmployeeID", employeeId)) Dim rrule As String = Nothing If apt.RecurrenceRule <> String.Empty Then rrule = apt.RecurrenceRule End If cmd.Parameters.Add(CreateParameter("@RecurrenceRule", rrule)) Dim parentId As Object = Nothing If apt.RecurrenceParentID IsNot Nothing Then parentId = apt.RecurrenceParentID End If cmd.Parameters.Add(CreateParameter("@RecurrenceParentId", parentId)) cmd.Parameters.Add(CreateParameter("@Annotations", "")) cmd.Parameters.Add(CreateParameter("@Description", apt.Description)) cmd.Parameters.Add(CreateParameter("@Reminder", apt.Reminders.ToString())) End SubEnd ClassPublic Class MySchedulerInfo Inherits SchedulerInfo Public Property StoreID() As String Get Return _storeid End Get Set(value As String) _storeid = value End Set End Property Private _storeid As Integer Public Sub New(baseInfo As ISchedulerInfo, storeid_1 As Integer) MyBase.New(baseInfo) StoreID = storeid_1 End Sub Public Sub New() End Sub Protected Overrides Sub Finalize() MyBase.Finalize() End SubEnd ClassThis is the Web.config file:
<?xml version="1.0"?><configuration> <connectionStrings> <!--SQL Server--> <!--<add name="POSDB" connectionString="4PWt4K/rc1CkfMOmzAtubPLsFJ51KNDs9YW8tXf54735pIwMePgOdWaP2DazZg5zj2NXHYnkQd36dZb1NwQTXRujp0Me64Xc/rzAVWrKuM/b9S5lBMc0f9oz8fBAxICfi8/ge9CHrY2NOwdysmDO9w=="/>--> <!--SQL Express--> <add name="POS" connectionString="8FkDM4EumAI6nH1h6twN/Gm9lV0cFp1kH22N3nFpqsTn/65a9ISM9mgbdczruCjHumIWrNtrUAsSJ9qdo710eIvP4HvQh62NjTsHcrJgzvc="/> </connectionStrings> <system.web> <compilation debug="true" strict="false" explicit="true" targetFramework="4.0" /> </system.web> <system.serviceModel> <behaviors> <serviceBehaviors> <behavior> <!-- To avoid disclosing metadata information, set the value below to false before deployment --> <serviceMetadata httpGetEnabled="true"/> <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --> <serviceDebug includeExceptionDetailInFaults="false"/> </behavior> </serviceBehaviors> </behaviors> <serviceHostingEnvironment > <!--<serviceActivations> <add factory="System.ServiceModel.Activation.WebServiceHostFactory" relativeAddress="AppointmentsWCF.svc" service="AppointmentsWCF.SchedulerWcfService"/> </serviceActivations>--> </serviceHostingEnvironment> </system.serviceModel> <system.webServer> <modules runAllManagedModulesForAllRequests="true"/> <!-- To browse web app root directory during debugging, set the value below to true. Set to false before deployment to avoid disclosing web app folder information. --> <directoryBrowse enabled="false"/> </system.webServer></configuration>The application with the RADScheduler is as follows.
This is the AppointmentDisplay.ascx code:
<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="AppointmentDisplay.ascx.vb" Inherits="Appointments.AppointmentDisplay" %><%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %><div><%-- <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" />--%> <telerik:RadAjaxManagerProxy ID="RadAjaxManagerProxy1" runat="server" ></telerik:RadAjaxManagerProxy><%-- <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" LoadingPanelID="RadAjaxLoadingPanel1">--%> <telerik:RadScheduler ID="RadScheduler1" runat="server" DataDescriptionField="Description" DataEndField="End" DataKeyField="ID" DataRecurrenceField="RecurrenceRule" DataRecurrenceParentKeyField="RecurrenceParentID" DataReminderField="Reminder" DataStartField="Start" DataSubjectField="Subject" GroupBy="Employee" Skin="Forest" StartInsertingInAdvancedForm="True" OnResourcesPopulating="RadScheduler1_ResourcesPopulating" > <ResourceTypes> <telerik:ResourceType ForeignKeyField="EmployeeID" KeyField="EmployeeID" Name="Employee" TextField="EmployeeName" /> <telerik:ResourceType ForeignKeyField="CustomerID" KeyField="CustomerID" Name="Customer" TextField="CustomerName" /> </ResourceTypes> <WebServiceSettings Path="http://localhost:3457/AppointmentsWCF.svc" ResourcePopulationMode="ServerSide" /> </telerik:RadScheduler><%-- </telerik:RadAjaxPanel>--%> <%-- <asp:SqlDataSource ID="DSAppointments" runat="server" ConnectionString="Data Source=192.168.1.10,427;Initial Catalog=POS;Persist Security Info=True;User ID=sa;Password=67Impala" ProviderName="System.Data.SqlClient" SelectCommand="AppointmentsSelect" SelectCommandType="StoredProcedure" DeleteCommand="AppointmentsDelete" DeleteCommandType="StoredProcedure" InsertCommand="AppointmentsInsert" InsertCommandType="StoredProcedure" UpdateCommand="AppointmentsUpdate" UpdateCommandType="StoredProcedure"> </asp:SqlDataSource> <asp:SqlDataSource ID="DSEmployees" runat="server" ConnectionString="Data Source=192.168.1.10,427;Initial Catalog=POS;Persist Security Info=True;User ID=sa;Password=67Impala" ProviderName="System.Data.SqlClient" SelectCommand="EmployeeAppointmentSelect" SelectCommandType="StoredProcedure" > </asp:SqlDataSource> <asp:SqlDataSource ID="DSCustomers" runat="server" ConnectionString="Data Source=192.168.1.10,427;Initial Catalog=POS;Persist Security Info=True;User ID=sa;Password=67Impala" ProviderName="System.Data.SqlClient" SelectCommand="CustomerAppointmentSelect" SelectCommandType="StoredProcedure" > </asp:SqlDataSource>--%></div>This is the codebehind:
Imports Telerik.Web.UIPublic Class AppointmentDisplay Inherits System.Web.UI.UserControl Private cnn As String Dim sStoreID As String Dim tabstrip As RadTabStrip Dim tab As RadTab Dim StoreID As HiddenField Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim crypto As Encryption.Crypto = New Encryption.Crypto("Suncoast") cnn = crypto.Decrypt(ConfigurationManager.ConnectionStrings("POS").ConnectionString) SetStoreID() BuildDSAppointments() BuildDSEmployees() BuildDSCustomers() BuildScheduler() End Sub Private Sub SetStoreID() tabstrip = Parent.FindControl("RadTabStrip1") tab = tabstrip.SelectedTab sStoreID = tab.Attributes.Item("StoreID").ToString StoreID = Parent.FindControl("StoreID") StoreID.Value = sStoreID End Sub Private Sub BuildScheduler() 'RadScheduler1.ID = "Scheduler" + sStoreID 'RadScheduler1.DataSourceID = DSAppointments.UniqueID 'RadScheduler1.ResourceTypes(0).DataSourceID = DSEmployees.UniqueID 'RadScheduler1.ResourceTypes(1).DataSourceID = DSCustomers.UniqueID End Sub Private Sub BuildDSAppointments() 'With DSAppointments ' .ID = "DSAppointments" + sStoreID ' .ConnectionString = cnn ' .SelectParameters.Clear() ' .SelectParameters.Add(New ControlParameter("StoreID", System.TypeCode.Int32, StoreID.UniqueID, "Value")) ' .DeleteParameters.Clear() ' .DeleteParameters.Add(New Parameter("ID", DbType.Int32)) ' .InsertParameters.Clear() ' .InsertParameters.Add(New ControlParameter("StoreID", System.TypeCode.Int32, StoreID.UniqueID, "Value")) ' .InsertParameters.Add(New Parameter("Subject", DbType.String)) ' .InsertParameters.Add(New Parameter("Start", DbType.DateTime)) ' .InsertParameters.Add(New Parameter("End", DbType.DateTime)) ' .InsertParameters.Add(New Parameter("CustomerID", DbType.Int32)) ' .InsertParameters.Add(New Parameter("EmployeeID", DbType.Int32)) ' .InsertParameters.Add(New Parameter("RecurrenceRule", DbType.String)) ' .InsertParameters.Add(New Parameter("RecurrenceParentID", DbType.Int32)) ' .InsertParameters.Add(New Parameter("Annotations", DbType.String)) ' .InsertParameters.Add(New Parameter("Description", DbType.String)) ' .InsertParameters.Add(New Parameter("Reminder", DbType.String)) ' .UpdateParameters.Clear() ' .UpdateParameters.Add(New ControlParameter("StoreID", System.TypeCode.Int32, StoreID.UniqueID, "Value")) ' .UpdateParameters.Add(New Parameter("Subject", DbType.String)) ' .UpdateParameters.Add(New Parameter("Start", DbType.DateTime)) ' .UpdateParameters.Add(New Parameter("End", DbType.DateTime)) ' .UpdateParameters.Add(New Parameter("CustomerID", DbType.Int32)) ' .UpdateParameters.Add(New Parameter("EmployeeID", DbType.Int32)) ' .UpdateParameters.Add(New Parameter("RecurrenceRule", DbType.String)) ' .UpdateParameters.Add(New Parameter("RecurrenceParentID", DbType.Int32)) ' .UpdateParameters.Add(New Parameter("Annotations", DbType.String)) ' .UpdateParameters.Add(New Parameter("Description", DbType.String)) ' .UpdateParameters.Add(New Parameter("Reminder", DbType.String)) ' .UpdateParameters.Add(New Parameter("ID", DbType.Int32)) 'End With End Sub Private Sub BuildDSEmployees() 'With DSEmployees ' .ID = "DSEmployees" + sStoreID ' .ConnectionString = cnn ' .SelectParameters.Clear() ' .SelectParameters.Add(New ControlParameter("StoreID", System.TypeCode.Int32, StoreID.UniqueID, "Value")) 'End With End Sub Private Sub BuildDSCustomers() 'With DSCustomers ' .ID = "DSCustomers" + sStoreID ' .ConnectionString = cnn ' .SelectParameters.Clear() ' .SelectParameters.Add(New ControlParameter("StoreID", System.TypeCode.Int32, StoreID.UniqueID, "Value")) 'End With End Sub 'Protected Sub RadScheduler1_FormCreated(sender As Object, e As SchedulerFormCreatedEventArgs) ' If (e.Container.Mode = SchedulerFormMode.AdvancedEdit) OrElse (e.Container.Mode = SchedulerFormMode.AdvancedInsert) Then ' 'finds the RadComboBox representing the user resource ' Dim customerResource As RadComboBox = TryCast(e.Container.FindControl("ResCustomer"), RadComboBox) ' 'this line of code will subscribe for the the client-side event fired when user selects a new value from the RadComboBox control ' customerResource.OnClientSelectedIndexChanging = "OnClientSelectedIndexChanging" ' End If 'End Sub Protected Sub RadScheduler1_ResourcesPopulating(sender As Object, e As ResourcesPopulatingEventArgs) Dim info As AppointmentsWCF.MySchedulerInfo = New AppointmentsWCF.MySchedulerInfo info.ViewStart = e.SchedulerInfo.ViewStart info.ViewEnd = e.SchedulerInfo.ViewEnd info.StoreID = sStoreID End SubEnd ClassI have been hacking away at this for almost a week and just can't get his to work! Anyone here that can help with this?
Thanks.
