[英]Stored Procedure to Web Service
I would like to know if there is an automatic (or effortless) way to map SQL Server stored procedures to web services? 我想知道是否有一种自动(或轻松)方式将SQL Server存储过程映射到Web服务?
The problem is, I need to allow a third party application to interact/integrate data with an ERP system. 问题是,我需要允许第三方应用程序与ERP系统交互/集成数据。 This ERP provides several stored procedures to do that.
该ERP提供了一些存储过程来实现这一目的。 Those stored procedures also contain validation and tons of business logic.
这些存储过程还包含验证和大量业务逻辑。
But, this external app prefers to go through web services. 但是,此外部应用程序更喜欢通过Web服务。
So, the first approach is to create a web service and map each stored procedure to a method (or may be split in different endpoints) but, I don't know is there is some tool, if it can be done using Entity Framework, etc. 因此,第一种方法是创建一个Web服务,并将每个存储过程映射到一个方法(或者可以拆分为不同的端点),但是,我不知道有没有某种工具,如果可以使用Entity Framework完成,等等
You could write something yourself using SMO (Sql management objects), if we are talking about 2 stored procs it may not be worth it but if its 100... 您可以使用SMO(Sql管理对象)自己编写一些东西,如果我们谈论的是2个存储过程,那么可能不值得,但是如果它是100个...
this is a demonstration to use SMO. 这是使用SMO的演示。 the same idea could be used for writing out your service contract etc.
同样的想法可以用来签出您的服务合同等。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Smo;
class Program
{
static void Main(string[] args)
{
Server srv = new Server("serverName");
Database db = srv.Databases["myDBName"];
foreach (StoredProcedure proc in db.StoredProcedures)
{
StringBuilder methodWriter = new StringBuilder();
methodWriter.Append("public void " + proc.Name + "(");
foreach(Parameter param in proc.Parameters)
{
string csharpData = string.Empty;
if (param.DataType == DataType.DateTime) { csharpData = "DateTime " + param.Name; }
//...
methodWriter.Append(csharpData + ", ");
}
methodWriter.Append("){}");
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.