简体   繁体   中英

Use .NET dll as COM

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:

在此处输入图片说明

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM