Use .NET dll as COM

和自甴很熟 提交于 2019-12-13 06:59:11

问题


I have a somewhat convoluted issue where I need to call a WCF web service from a SQL Server 2005 stored procedure.

While researching I discovered that the only version of .NET SQL Server 2005 will natively support it 2.0 - yet I needed to use a client to consume the web service written for .NET 4. After playing around with some workaround to try to get SQL Server to recognize a .NET 4 DLL I decided to simply create a .NET 2 CLR stored procedure and use a wrapper class written in .NET 4 exposed as COM in order to call my web service.

I found several guides dealing with how to use a .NET 4 dll with .NET 2 as a COM dll (link, link) yet am still struggling.

My "wrapper class" (.NET 4) looks like this:

namespace Wrapper
{
    [Guid("4C1D992C-4965-49B2-A694-33810A3B9775")]
    [ComVisible(true)]
    public class WrapperClass
    {
         public bool Process(Guid ID)
         {
         }
    }
}

I've added the app.manifest file as suggested by the second link above. However, when I add the generated DLL to my .NET 2 sql server project, it fails to build with the following message:

1>c:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1578,5): Warning:  MSB3274: The primary reference "Wrapper" could not be resolved because it was built against the ".NETFramework,Version=v4.0" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v2.0".

What am I doing wrong here? I tried not adding the DLL as a reference at all but then the code does not even compile.

Alternatively, is there another (easier) way I can approach this issue?

EDIT: I can't directly add a web reference either:


回答1:


I ended up just using John Koerner's suggestion and generating a client using WSDL that didn't use System.ServiceModel. As a result I made my CLR assembly .net 2.0 and it worked fine.



来源:https://stackoverflow.com/questions/14590295/use-net-dll-as-com

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!