我有 Visual Studio 2013。
我创建了一个数据库项目。
我向该项目添加了一个 CLR 存储过程,我想从中调用 WCF 服务。
谁能帮我?
我希望能够在不更改程序集的情况下更改服务地址,类似于我可以在WCF 客户端配置部分中web.config
执行的操作。endpoint
我有 Visual Studio 2013。
我创建了一个数据库项目。
我向该项目添加了一个 CLR 存储过程,我想从中调用 WCF 服务。
谁能帮我?
我希望能够在不更改程序集的情况下更改服务地址,类似于我可以在WCF 客户端配置部分中web.config
执行的操作。endpoint
经过大量搜索后我发现了这一点,并在 VS 2014 中花了很多时间
Database Project
名为“CLR_Test” Library
为 WCF 客户端“CLR_Service_Client” 创建将Serivce Refrence
wcf 服务添加到“CLR_Test”,然后将“CLR_Service_Client”的引用添加到“CLR_Test”
4.您必须更改 DB 选项才能使用以下代码运行不安全的程序集
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 标头/本机存根。对于我们想要做的事情来说,这本来是一个美妙而优雅的解决方案,但微软再次让我们悬在悬崖边