How to call WCF Ria Service / DomainService from jQuery?

I am trying to call a DomainService created using WCF Ria services from jquery. If I use POST, I get a 405 method not allowed. If I use Get, it will get javascript errors. Am I missing a configuration step? This code leads to 405.

    function GetSearchResults() {
        $.ajax(
    {
        type: "POST",
        url: "/Services/CustomerService.svc/GetCustomerSearchResults",
        data: '{"customerId":1}',
        timeout: 5000,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: Success,
        error: Fail
    });
    }

[EnableClientAccess]
public class CustomerService : DomainService
{
    public List<CustomerSearchResult> GetCustomerSearchResults(string customerId)
    {


        var list = new List<CustomerSearchResult>();
        list.Add(new CustomerSearchResult
            {
              Id = 1,
                                   Name = "Me"
            });
        }

        return list;
    }

}

+3
source share
2 answers

Although his old post, but for future projects, looks great ...

http://jeffhandley.com/archive/2011/04/13/RIAJS-jQuery-client-for-WCF-RIA-Services.aspx

0
source

It is a little harder than that. This article explains how to connect jQuery with WCF.

+1
source

Source: https://habr.com/ru/post/1726255/


All Articles