Can Ajax-enabled WCF service return DataTable as Sys.Data.DataTable?

Can Ajax-enabled WCF service return DataTable as Sys.Data.DataTable? Like this , but in WCF.

My OperationContract looks like this:

    [OperationContract]
    public DataTable GetEmployees()
    {
        NorthwindService ns = new NorthwindService();
        return ns.GetEmployees();
    }

      

Through the Firefox error console I get the message:
Error: Item Not Found - Source File: http: // localhost: 4845 / TestWcfAjax / SomeService.svc / GetEmployees

If I enter this URL (at the top) into the browser, I get:
Method not allowed.

I have another method that just returns a string that works through WCF / ASP.NET Ajax.
Thoughts? Troubleshooting tips?

code is missing code Edit / add code:
The code does not define how to paste the code here in a readable way the
code located here:
http://www.mirc.org/paste/92

+1


source to share


1 answer


You are getting the error Method not allowed

because the default HTTP verb for web service calls is POST, and when you just enter the url in your web browser the GET verb. Use an HTTP debugger tool like Fiddler to simulate POST requests. Also show the code that calls this service, so we can see the problem.

PS. Also, from what I remember, I think you cannot just return the DataTable from the web service call, you need to have it inside the DataSet so it serializes correctly.

Ok, I figured out that the GET verb was the question. Any way to allow the GET request for troubleshooting? Is there a client-side Sys.Data.DataSet? I have Fiddler installed I will try this. - Bruno Tyndall (9 minutes ago) [delete this comment]



No, there is no client side DataSet data structure, you just get XML back that you can parse. To enable GET instead of POST, decorate your operation with the following additional attribute:

[ WebInvoke( Method = "GET", BodyStyle = WebMessageBodyStyle.Bare,
  RequestFormat = WebMessageFormat.Xml,
  ResponseFormat = WebMessageFormat.Xml ) ]

      

+3


source







All Articles