You must be making that mistake:
That is, failure to authenticate, to get around such problem goes in the folder App_Start
, open the file RouteConfig.cs
and left so, being that in the second line put as RedirectMode.Off
public static class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
var settings = new FriendlyUrlSettings();
settings.AutoRedirectMode = RedirectMode.Off;
routes.EnableFriendlyUrls(settings);
}
}
Ready will work immediately.
A tip: make a WebService.asmx
:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
namespace WebApplication2
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class WebServiceDados : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
[WebMethod()]
public List<string> MontarGrafico()
{
var l = new List<string>();
l.Add("teste1");
l.Add("teste2");
return l;
}
}
}
Javascript Ajax:
$.ajax({
type: "POST",
url: "WebServiceDados.asmx/MontarGrafico",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (produtos) {
var prods = produtos.d;
$.each(prods, function (index, prod) {
alert(prod);
});
}
});
In this mode you don’t need to touch that setting RouteConfig.cs
Another point to note is the sending and receiving, configure your jsonSerialization
on your Webconfig, to receive/send data with large sizes
<configuration>
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="50000000"/>
</webServices>
</scripting>
</system.web.extensions>
</configuration>
Note: to check the errors I install the Firebug Lite, a widely used plugin that picks errors Javascript
by browser.
I added Webservice.asmx, and it worked. How do I view that part of the Post? The print you put up?
– Diego Zanardo
I use a plugin in google Chrome Firebug Lite: https://getfirebug.com/firebuglite
– user6026