Reputation: 71131
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
Upvotes: 1
Views: 2004
Reputation: 51461
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 ) ]
Upvotes: 3