I have a simple report in SSRS 2008 R2 that I've modified to allow the user to directly enter comments into textboxes. When the user exits the textbox I use jQuery AJAX to save the user's comments to the database via a webmethod in another aspx page.
Using POST I get the error: "HttpException (0x80004005): The HTTP verb POST used to access path '/Reports_SQL2008R2/Pages/test.aspx/SaveComments' is not allowed."
Using GET I get the error: "HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable"
Web.config (Reporting Services/ReportManager/Web.config)
<system.web>
<webServices>
<protocols>
<add name="HttpPost"/>
<add name="HttpGet"/>
</protocols>
</webServices>
</system.web>
ReportingServices.js (Reporting Services/ReportManager/ReportingServices.js - append to end of script)
function addScript(scriptFile)
{
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.setAttribute('language', 'JScript');
script.setAttribute('type', 'text/javascript');
script.setAttribute('src', scriptFile);
head.appendChild(script);
}
addScript('//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js');
function pageLoad() {
// Fix for report not rendering in Chrome/Safari:
// see: http://stackoverflow.com/questions/5428017/cannot-view-ssrs-2008-r2-ssrs-2012-reports-in-safari-chrome-but-works-fine-in
var element = document.getElementById("ctl31_ctl10"); // might also have been "ctl31_ctl09"
if (element) {
element.style.overflow = "visible";
}
// Test ajax
if (typeof jQuery != 'undefined') {
$.ajax({
type: "POST",
url: "test.aspx/SaveComments",
data: '{}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data, textStatus, jqXHR) {
alert("Success");
},
error: function (jqXHR, textStatus, errorThrown) {
alert(errorThrown);
}
});
}
}
Test.aspx (Reporting Services/ReportManager/Pages/Test.aspx)
<%@ Page language="C#" CodeFile="Test.aspx.cs" AutoEventWireup="true" Inherits="Examples.Test" %>
Test.aspx.cs (Reporting Services/ReportManager/Pages/Test.aspx)
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
namespace Examples
{
public partial class Test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[WebMethod]
public static string SaveComments(string test)
{
return "YES!";
}
}
}
[Edit]
I was unable to solve this problem. I had hoped to simply add a web method to the Reporting Services website but I can't figure out these permissions problems. My workaround has been to create a web service, but this is a bit messier because I now have to do a cross domain request:
WebService2.asmx
<%@ WebService Language="C#" Class="WebService2" %>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Script.Services;
using System.Web.Script.Serialization;
using System.Text;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class WebService2 : System.Web.Services.WebService
{
[WebMethod]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public string HelloWorld(string commentKey, string commentValue, string callback)
{
StringBuilder sb = new StringBuilder();
JavaScriptSerializer js = new JavaScriptSerializer();
sb.Append(callback + "(");
sb.Append(js.Serialize(new{commentKey = commentKey, commentValue = commentValue}));
sb.Append(");");
Context.Response.Clear();
Context.Response.ContentType = "application/json";
Context.Response.Write(sb.ToString());
Context.Response.End();
return "Hello World two";
}
}
ReportingServices.js (partial)
$.ajax({
type: "POST",
url: "http://localhost/WebApplication3/WebService2.asmx/HelloWorld?commentKey=KEY&commentValue=VALUE",
contentType: "application/javascript",
dataType: "jsonp",
success: function (data, textStatus, jqXHR) {
$this.each(switchToSpan);
},
error: function (jqXHR, textStatus, errorThrown) {
alert(errorThrown);
$(this).focus();
}
});