简体   繁体   English

WCF和MVC:从Web MVC应用程序调用存储过程

[英]WCF and MVC : Call stored procedures from web mvc application

I've done a wcf service that deals with a database. 我已经完成了处理数据库的wcf服务。 In that WCF service i've created some stored procedures. 在该WCF服务中,我创建了一些存储过程。 That service is now accessible from my network (http: //myIP/MysService.csv/) and my stored procedures are accessible that way : http: //myIP/MysService.csv/MyProcedure?myParam=XXX. 现在可以从我的网络(http://myIP/MysService.csv/)访问该服务,并且可以通过以下方式访问我的存储过程:http://myIP/MysService.csv/MyProcedure?myParam=XXX。

I've a MVC4 application that is working with some local data (by local I mean a local database and a local WCF service, called that way for requests by example : 我有一个正在使用某些本地数据的MVC4应用程序(本地是指本地数据库和本地WCF服务,以示例的方式称为请求:

public int getClientID(string login)
    {
        var context = new MyLocalService.MyLocalEntityEntities(new Uri(http://localhost:12345/MyWCF.svc/));
        var persons = context.PERSON.ToList();

        var cli = from person in persons
                     where person.LOGIN == login
                     select person.CLIENT_ID;

        int cliID = (int) cli.First();
        return cliID;
    }

Now, I'd like to plug the 2 : delete all the part that works with local data (var context=...) and replace it by a call to the stored procedure of my WCF service. 现在,我想插入2:删除所有与本地数据一起使用的部分(var context = ...),并通过调用WCF服务的存储过程来替换它。 How to do it ? 怎么做 ?

I've try to add my service using right click-> add as a service reference -> http: //myIP/MysService.csv/ for address by I cannot access to stored procedures. 我尝试使用右键单击->添加为服务引用-> http://myIP/MysService.csv/作为地址添加我的服务,因为我无法访问存储过程。 Is it the right way to work and if not, how to do it ? 这是正确的工作方式吗?如果没有,怎么做? Thanks ! 谢谢 !

If you're going to use Stored Procedures then look at the SqlCommand class that will allow you to execute stored procedures on the database. 如果要使用存储过程,请查看SqlCommand类,该类将允许您在数据库上执行存储过程。

The other idea would be to consider what kind of Object-Relational Mapping tool you are using that may allow for SQL commands to be executed directly since you already seem to be using some LINQ in your code. 另一个想法是考虑使用哪种对象关系映射工具,因为您似乎已经在代码中使用了某些LINQ,因此可以直接执行SQL命令。


You'd pair the SqlCommand class with a SqlConnection class that have a direct connection to the database, presuming the stored procedure is MS-SQL Server or SQL Express where you want to execute the procedure in the DB. 您可以将SqlCommand类与直接连接到数据库的SqlConnection类配对,假定存储过程是MS-SQL Server或SQL Express,您想在其中执行数据库中的过程。 Unless you have a very different configuration than what I've seen, most calls to stored procedures are done by wrapping some using statements for the connection and command to run the procedure. 除非您的配置与我所看到的完全不同,否则对存储过程的大多数调用都是通过包装一些using语句来完成的,而该语句用于连接和运行该过程的命令。 Calling stored procedure from C# code has an example if you need it. 如果需要,可以使用C#代码调用存储过程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 WCF MVC调用存储过程 - WCF MVC calling stored procedures 如何从MVC Web API调用WCF服务并绑定模型? - How to call WCF service from MVC web api and bind model? C#MVC体系结构,我应该从MODEL还是CONTROLLER调用存储过程 - C# MVC architecture, should I call stored procedures from MODEL or CONTROLLER 具有EntityFramework模型作为存储过程的MVC - MVC with EntityFramework model as stored procedures MVC 4-报告服务和存储过程 - MVC 4 - Reporting Service and Stored Procedures 在MVC Web应用程序中托管WCF服务 - Hosted WCF service inside MVC Web application MVC 5,EF 6和“数据库中的代码优先”存储过程 - MVC 5, EF 6, and “Code First from Database” Stored Procedures 从具有集成Windows身份验证的MVC应用程序调用Web API - Call Web API from MVC Application with Integrated Windows Authentication 从MVC控制器异步调用WCF服务 - Asynchronous call to WCF service from MVC controller 存储过程体系结构 - 我的MVC应用程序应该处理存储过程,还是应该像“工作者角色”那样处理它? - Stored procedures architecture - should my MVC application be handling stored procedures, or should something akin to a “worker role” take care of it?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM