views:

1125

answers:

1

Can an Ajax-enabled WCF Service pass back a DataTable as a Sys.Data.DataTable? Like this but in WCF.

My OperationContract looks like:

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

Through the Firefox error console I get the message:
Error: no element found
Source File: http://localhost:4845/TestWcfAjax/SomeService.svc/GetEmployees

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

I have another method which just returns a string that does work via WCF/ASP.NET Ajax.
Thoughts? Troubleshooting ideas?

there is no code in the code behind
Edit / Added Code:
Code not figure out how to paste code here in a readable way
code located here:
http://www.mirc.org/paste/92

+3  A: 

You get the Method not allowed error, because the default HTTP verb for the web service calls is POST, and when you just type the URL in the web browser, the verb is GET. Use an HTTP debugger tool, like Fiddler to simulate POST requests. Also show code that calls this service, so we can see the problem.

PS. Also from what I remember, I think you can't just return a DataTable from a web service call, you need to have it inside a DataSet, so it gets serialized properly.

Ok I figured the GET verb was an issue. Any way to allow a GET request for troubleshooting? Is there a client-side Sys.Data.DataSet ? I have fiddler installed I'll try that. – Bruno Tyndall (9 mins ago) [remove this comment]

No, there is no client-side DataSet structure, you will 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 ) ]
Strelok
Ok I figured the GET verb was an issue. Any way to allow a GET request for troubleshooting? Is there a client-side Sys.Data.DataSet ? I have fiddler installed I'll try that.
tyndall
Does fiddler not work if its not being served from a standard port? The URL - http://localhost:4845/TestWcfAjax/TestPage.aspx is passing right through without being logged by fiddler.
tyndall
Bare did not work. [OperationContract][WebInvoke(Method = "GET",BodyStyle = WebMessageBodyStyle.WrappedRequest,RequestFormat = WebMessageFormat.Xml,ResponseFormat = WebMessageFormat.Xml)]public DataTable GetEmployees(){ NorthwindService ns = new NorthwindService();return ns.GetEmployees();}
tyndall
I did the above and now when I go to the URL:http://localhost:4845/TestWcfAjax/SomeService.svc/GetEmployeesI get nothing. Does this mean its passing back null or something? I have already tested the DataTable return from another page on a GridView control. So I know the method works.
tyndall