WCF WebService Not Returning DataTable -
i beginning use wcf write web service instead of old asp.net asmx way. want able return json can't old way. if returning string or int web service works fine if try return datatable becomes unresponsive , nothing. have tried debugging see blows , won't stop on breakpoint.
my class file looks this:
public string xmldata(string id) { return "you requested " + id; } public string jsondata(string id) { return "you requested " + id; } public datatable testdt() { datatable testing = new datatable("testdt"); return testing; }
my interface file looks this:
[operationcontract] [webinvoke(method = "get", responseformat = webmessageformat.xml, bodystyle = webmessagebodystyle.wrapped, uritemplate = "xml/{id}")] string xmldata(string id); [operationcontract] [webinvoke(method = "get", responseformat = webmessageformat.json, bodystyle = webmessagebodystyle.wrapped, uritemplate = "json/{id}")] string jsondata(string id); [operationcontract] [webinvoke(method = "get", responseformat = webmessageformat.json, bodystyle = webmessagebodystyle.wrapped, uritemplate = "testdt/")] datatable testdt();
the json
method xml
method works fine. when call testdt standard ie page showing no connectivity. have tried data or no data in datable same results.
one other note here: when run wcf service locally (hitting play) test application shows services see this:
how can work datable?
edit#1: resolved issue data not returning. gave on trying return dataset , instead created jagged array , ended return json. i'll post later answer people know how did it. more interested in knowing part 2. why wcf test client not showing methods (see image attached) hunch related web.config posting below:
<?xml version="1.0"?> <configuration> <connectionstrings> <add name="dbdjugglews" connectionstring="data source=localhost;initial catalog=prayupdev;persist security info=true;user=djugglemaster;password=djpassword!" providername="system.data.sqlclient"/> </connectionstrings> <system.web> <compilation debug="true" targetframework="4.0" /> </system.web> <system.servicemodel> <services> <service name ="prayupservice.prayup" behaviorconfiguration="servicebehaviour"> <endpoint address="" binding="webhttpbinding" contract="prayupservice.iprayup" behaviorconfiguration ="web"></endpoint> </service> </services> <behaviors> <servicebehaviors> <behavior name="servicebehaviour"> <!-- avoid disclosing metadata information, set value below false , remove metadata endpoint above before deployment --> <servicemetadata httpgetenabled="true"/> <!-- receive exception details in faults debugging purposes, set value below true. set false before deployment avoid disclosing exception information --> <servicedebug includeexceptiondetailinfaults="true"/> </behavior> </servicebehaviors> <endpointbehaviors> <behavior name="web"> <webhttp/> </behavior> </endpointbehaviors> </behaviors> <servicehostingenvironment multiplesitebindingsenabled="true" /> </system.servicemodel> <system.webserver> <modules runallmanagedmodulesforallrequests="true"/> </system.webserver> </configuration>
you shoud return dataset
instead of datatable
returning data sets web services not typically considered “good practice”. here can read it: why returning dataset or data table wcf service not practice? alternatives?
i highly recommend use dataset’s
methods data in xml format , pass xml string instead of dataset
service.
passdataset(dsdataset.getxmlschema(), dsdataset.getxml())
Comments
Post a Comment