I have been working for a while now on a project that will be using JQueryUI autocompletes for user names (based on SPWeb.AllUsers) and will also be pulling content from a potentially large list separately in the same form. I initially attempted a page method and could not manage to get a return other than the whole page html (despite setting content type, etc), and so have moved on to attempting it via ASMX. The result of this is a 500. Running through Fiddler gave me the full ASP error: "The file you are attempting to save or retrieve has been blocked from this Web site by the server administrators." I'm fairly certain the code inside the method is not being hit, as a breakpoint set on the first line of the method is not triggered.
Here's my web service:
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class projectWebService : System.Web.Services.WebService
{
public class person
{
public person(string name, string company)
{
this.name = name;
this.company = company;
}
public string name { get; set; }
public string company { get; set; }
}
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static string getNames()
{
try
{
//Query list to filter by company and sort by name
var userQuery = from SPUser user in SPContext.Current.Web.AllUsers
orderby user.Name ascending
select user;
List<person> userList = new List<person>();
foreach (SPUser user in userQuery)
{
userList.Add(new person(user.Name, "something"));
}
JavaScriptSerializer serializer = new JavaScriptSerializer();
return serializer.Serialize(userList);
}
catch (Exception ex)
{
return ex.Message;
}
}
}
I've tried a few variations on this with the same result. And here's the AJAX call:
$.ajax({
type: 'POST',
dataType: 'json',
data: '{}',
contentType: 'application/json; charset=utf-8',
url: 'projectWebService.asmx/getNames',
success: function (msg) {
alert(msg.toString());
var people = $.parseJSON(msg);
$('#projectManager').autocomplete({
source: people
});
},
error: function (xhr, msg, error) {
alert(msg.toString());
alert(error);
}
});
Attempting to set "UseHttpGet" and making a GET request has been unsuccessful as well.
I found one related question here: This one mentions a web.config entry that may be the culprit. I have set this to no avail.
Also, this article covers other web.config changes that may(?) be required. This did not work for me, instead getting an ASP error for an invalid web.config.
I'm hoping someone has either had to deal with this before or sees something I do not. Thanks for any help!