我有 Visual Studio 2013。
我创建了一个数据库项目。
我向该项目添加了一个 CLR 存储过程,我想从中调用 WCF 服务。
谁能帮帮我?
我希望能够在不更改程序集的情况下更改服务地址,类似于我在 web.config
中使用我的 WCF 客户端配置的 endpoint
部分所做的事情。
最佳答案
经过大量搜索后我发现了这个,并在 VS 2014 中花了很多时间
- 创建名为“CLR_Test”的
数据库项目
- 为 WCF 客户端“CLR_Service_Client”创建
库
将wcf服务的
Service Refrence
添加到“CLR_Test”,然后将“CLR_Service_Client”的refrence添加到“CLR_Test”
4.您必须更改数据库选项以能够使用以下代码运行不安全的程序集ALTER DATABASE SaleAutomation SET TRUSTWORTHY ON 重新配置
在
SQLCLR
选项卡的“CLR_Test”Project Properties
中,将Permission level
设置为Unsafe
(另一种方法是在发布项目后从 sql server 管理更改其级别,另一种方法是将权限级别添加到发布脚本,您可以使用它们中的每一个,
但你必须注意到,如果你使用project properties
只有“CLR_Test”项目自动创建Unsafe
并且你必须使用其他方式设置“CLR_Service_Client”Unsafe
)
6.运行这个脚本来添加Sqlserver可以运行wcf服务
CREATE ASSEMBLY
SMDiagnostics from
'C:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation\SMDiagnostics.dll'
with permission_set = UNSAFE
GO
CREATE ASSEMBLY
[System.Web] from
'C:\Windows\Microsoft.NET\Framework64\v2.0.50727\System.Web.dll'
with permission_set = UNSAFE
GO
CREATE ASSEMBLY
[System.Messaging] from
'C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Messaging.dll'
with permission_set = UNSAFE
GO
CREATE ASSEMBLY
[System.IdentityModel] from
'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.0\System.IdentityModel.dll'
with permission_set = UNSAFE
GO
CREATE ASSEMBLY
[System.IdentityModel.Selectors] from
'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.0\System.IdentityModel.Selectors.dll'
with permission_set = UNSAFE
GO
CREATE ASSEMBLY -- this will add service modal
[Microsoft.Transactions.Bridge] from
'C:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation\Microsoft.Transactions.Bridge.dll'
with permission_set = UNSAFE
GO
CREATE ASSEMBLY -- this will add service modal
[System.Runtime.Serialization] from
'C:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation\System.Runtime.Serialization.dll'
with permission_set = UNSAFE
GO
CREATE ASSEMBLY -- this will add service modal
[System.ServiceModel] from
'C:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation\System.ServiceModel.dll'
with permission_set = UNSAFE
GO
- 现在您可以发布您的项目并运行存储过程并尽情享受。
关于c# - SQL 服务器 CLR : how to call WCF Service In CLR SQL stored procedure in database project,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25316738/