问题描述:

I have a stored procedure for authentication, taking login and password and returning a string . I would like to call the stored procedure(sql server 2005) from my WCF data service ( using entity model and function imports ) and return the output parameter( string ) as the result .

I am using function import to map the stored procedure. How should I proceed ?

网友答案:

Finally, got the answer !! We have to use Output parameter , give it as an argument to the called stored procedure and finally just by a type cast we can use the value . ( My return format is JSON but it is equally valid for XML format) Interface : [OperationContract] [WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, UriTemplate = "authenticate/{login}/{pwd}")]

Implementation: 
public string authenticate(string login, string pwd)
{
SteelcaseMigrationEntities entities = new SteelcaseMigrationEntities();

System.Data.Objects.ObjectParameter output =  
new     System.Data.Objects.ObjectParameter("out", typeof(string));
entities.authenticate_android(login, pwd, output);
//Console.Write(output.Value)
string result = (string)output.Value;
return result;
}
相关阅读:
Top