Как решить только веб-сервисы с атрибутом [Scraptservice] в определении класса можно вызвать из скрипта

я пытаюсь использовать Webservice Return Poco Class, генерируемый из модели данных объекта как JSON, при использовании метода jQuery Ajax Call в Webservice. Но у меня проблема с ошибкой« Только веб-сервисы с атрибутом [Scraptservice] в определении класса можно вызвать из скрипта «, и застрял в нем,

вот мой код:

namespace CarCareCenter.Web.Admin.Services
{
    /// <summary>
    /// Summary description for About
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class About : System.Web.Services.WebService
    {
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        [WebMethod]
        public static Entities.Category getAbout()
        {
            Entities.Category about = new Entities.Category();
            using (var context = new CarCareCenterDataEntities())
            {
                about = (from c in context.Categories where c.Type == "About" select c).SingleOrDefault();
            }

            return about;
        }
    }
}

Страница ASPX:

<script type="text/javascript">
        $(document).ready(function () {
            $.ajax({
                type: 'POST',
                dataType: 'json',
                contentType: 'application/json; charset=utf-8',
                url: '/Services/About.asmx/getAbout',
                data: '{}',
                success: function (response) {
                    var aboutContent = response.d;
                    alert(aboutContent);
                    $('#title-en').val(aboutContent.Name);
                    $('#title-vn').val(aboutContent.NameVn);
                    $('#content-en').val(aboutContent.Description);
                    $('#content-vn').val(aboutContent.DescriptionVn);
                    $('#id').val(aboutContent.CategoryId);
                },
                failure: function (message) {
                    alert(message);
                },
                error: function (result) {
                    alert(result);
                }
            });



            $('#SaveChange').bind('click', function () { updateAbout(); return false; });
            $('#Reset').bind('click', function () { getAbout(); return false; })
        });

        function updateAbout() {
            var abt = {
                "CategoryId": $('#id').val(),
                "Name": $('#title-en').val(),
                "NameVn": $('#title-vn').val(),
                "Description": $('#content-en').val(),
                "DescriptionVn": $('#content-vn').val()
            };
            $.ajax({
                type: "POST",
                url: "AboutManagement.aspx/updateAbout",
                data: JSON.stringify(abt),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (response) {
                    var aboutContent = response.d;
                    $('#title-en').val(aboutContent.Name);
                    $('#title-vn').val(aboutContent.NameVn);
                    $('#content-en').val(aboutContent.Description);
                    $('#content-vn').val(aboutContent.DescriptionVn);
                },
                failure: function (message) {
                    alert(message);
                },
                error: function (result) {
                    alert(result);
                }
            });
        }
    </script>

Есть ли какие-либо подходы для ее решения? Пожалуйста, помогите мне. Спасибо

20
задан NevenHuynh 13 September 2011 в 18:18
поделиться