سؤال

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;
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top