Привет, я прошел через эту ошибку и не могу понять, как ее исправить. У меня есть служба RESTful WCF, пытающаяся извлечь данные из базы данных SQL Server. Благодарю.Ошибка службы WCF RESTful
Error 1 'RestService.RestServiceImpl.GetCompany(string)': not all code paths return a value
Мои кодирования
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 at GetCompany
public Company GetCompany(string CompID)
{
Company comp = new Company();
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "";
con.Open();
SqlCommand cmd = new SqlCommand("SELECT COMPANYNAME FROM 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; }
}
}
Ах так глупо спасибо! @Sajeetharan –
@RenaldoGeldenhuis welcome – Sajeetharan