mardi 4 août 2015

WCF Service - using AJAX to pass stored procedure name as data

I am writing a webpage which displays many different charts, using AJAX to get the data from the database and google charts to display the information.

Is there a way that I can pass in the stored procedure name from AJAX to the code behind webMetod? At the moment I am having to create a separate webMethod for each stored procedure whereas I would like to just have one method where I pass which procedure to call.

I have tried adding as a parameter and data but have not been able to make it work.

I am using WCF service to pull data from the database, here is my WebMethod, you will see the stored proc name 'GetChartDataConceptDoubleLayerComboTwoBars' which I would like to pass as a param.

[WebMethod]
public static List<ChartData> GetDoubleLayerChartTwoBars()
{
    System.ServiceModel.BasicHttpBinding userHttpBinding = new System.ServiceModel.BasicHttpBinding();
    userHttpBinding.ReaderQuotas.MaxStringContentLength = int.MaxValue;
    userHttpBinding.MaxReceivedMessageSize = int.MaxValue;
    System.ServiceModel.EndpointAddress userHtpEndpointAddress = new System.ServiceModel.EndpointAddress(chartDataDoubleLayerFactoryURI);
    ChartDataDoubleLayerTDFactory chartFactory = new ChartDataDoubleLayerTDFactory(userHttpBinding, userHtpEndpointAddress);

    TDBindingList<ChartDataDoubleLayerTD> chartDataRaw = chartFactory.GetChartDataConceptDoubleLayerComboTwoBars();

    List<ChartData> chartData = new List<ChartData>();
    chartData = channelReportingSummary.getData(chartDataRaw);

    chartFactory.Close();

    return chartData;
}

Here is the Ajax

$.ajax({
    type: 'POST',
    contentType: 'application/json; charset=utf-8',
    processData: false,
    url: 'http://ift.tt/1KOwoMR',
    dataType: 'json',
    timeout: 120000,
    async: false,
    success: function(result) {
        createDatatableCombo(result, data, options);
    },
    error: function(xhr) {
        alert(xhr.responseText);
    }
});

Aucun commentaire:

Enregistrer un commentaire