我有Visual Studio 2013。
我创建了一个数据库项目。
我向该项目添加了CLR存储过程,并希望从中调用WCF服务。
有人可以帮我吗?
我希望能够在不更改程序集的情况下更改服务地址,这与在WCF客户端配置的web.config
部分中在endpoint
中执行的操作类似。
我经过大量搜索后发现了这一点,并在VS 2014中花了很多时间
Database Project
称为“ CLR_Test”Library
将wcf服务的Serivce Refrence
添加到“ CLR_Test”,然后将“ CLR_Service_Client”的引用添加到“ CLR_Test”4.您必须使用以下代码更改数据库选项以能够运行不安全的程序集
ALTER DATABASE SaleAutomation SET TRUSTWORTHY ON
RECONFIGURE
在Project Properties
选项卡的“ CLR_Test” SQLCLR
中将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
自.Net v4.0起,所有这些都无济于事,System.ServiceModel是混合的MSIL,这意味着它将使用本机代码生成:
为程序集“ System.ServiceModel”创建组件失败,因为程序集“ microsoft.visualbasic.activities.compiler”格式错误或不是纯.NET程序集。不可验证的PE标头/本机存根。对于我们想做的事情,这本来是一个绝妙的优雅解决方案,但是微软再次让我们垂涎三尺