c# - WCF RESTful Service Error -
hi came accross error , cant figure out how fix it. have restful wcf service trying retrieve data sql server database. thanks.
error 1 'restservice.restserviceimpl.getcompany(string)': not code paths return value
my coding
restserviceimpl.svc.cs
public class restserviceimpl : irestserviceimpl { public string xmldata(string id) { return ("you requested product" + id); } public string jsondata(string id) { return ("you requested product" + id); } //error underlined @ getcompany public company getcompany(string compid) { company comp = new company(); { sqlconnection con = new sqlconnection(); con.connectionstring = ""; con.open(); sqlcommand cmd = new sqlcommand("select companyname tblcompany", con); con.open(); sqldatareader reader = cmd.executereader(); } } } }
irestservice.cs
public interface irestserviceimpl { [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] [webget(uritemplate = "/getcompany/{compid}", requestformat = webmessageformat.json, responseformat = webmessageformat.json)] company getcompany(string compid); } [datacontract] public class company { [datamember] public string compid { get; set; } [datamember] public string company { get; set; } } }
you need change method return type of object 'company'
public company getcompany(string companyname) { company comp = new company(); { sqlconnection con = new sqlconnection(); con.connectionstring = ""; con.open(); sqlcommand cmd = new sqlcommand("select companyname tblcompany", con); con.open(); sqldatareader reader = cmd.executereader(); //your implementation } return comp ; }
Comments
Post a Comment