WCF服务——返回实体模型中存储过程的输出参数

时间:2022-04-14 00:40:11

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 .

我有一个用于身份验证的存储过程,获取登录名和密码并返回一个字符串。我想从WCF数据服务(使用实体模型和函数导入)调用存储过程(sql server 2005)并返回输出参数(string)作为结果。

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

我正在使用函数导入来映射存储过程。我该如何继续?

1 个解决方案

#1


0  

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}")]

最后,得到了答案!!我们必须使用Output参数,将它作为被调用的存储过程的参数,最后通过类型转换我们可以使用这个值。接口:[OperationContract] [WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle = " WebMessageBodyStyle "。包装,ResponseFormat = WebMessageFormat。Json,RequestFormat = WebMessageFormat。Json,UriTemplate = "验证/ {登录} / { 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;
}

#1


0  

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}")]

最后,得到了答案!!我们必须使用Output参数,将它作为被调用的存储过程的参数,最后通过类型转换我们可以使用这个值。接口:[OperationContract] [WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle = " WebMessageBodyStyle "。包装,ResponseFormat = WebMessageFormat。Json,RequestFormat = WebMessageFormat。Json,UriTemplate = "验证/ {登录} / { 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;
}