简体   繁体   English

从Excel调用包含WCF Web服务的C#DLL

[英]Calling C# DLL that contains WCF web service from Excel

This question has been asked previously but my circumstances are slightly different. 之前已经问过这个问题,但我的情况略有不同。

I have an Excel add-in that we distribute to our users that now needs to connect to a downstream system. 我有一个Excel加载项,我们分发给我们的用户,现在需要将其连接到下游系统。 That downstream system have provided me a WCF webservice to do this with so I designed a C# DLL wrapper that I could expose through COM that would communicate to the WCF webservice and return the results through a COM interface to Excel. 那个下游系统为我提供了WCF Web服务,因此我设计了一个C#DLL包装器,可以通过COM公开该包装器,该包装器将与WCF Web服务进行通信并将结果通过COM接口返回给Excel。

I have Excel talking to the COM wrapper fine now, though I have had to revert to Framework 3.5 for the DLL for reasons I have yet to fathom to do with Excel and .NET runtime versions. 我现在让Excel与COM包装程序通信很好,尽管由于我还不了解Excel和.NET运行时版本的原因,我不得不恢复DLL的Framework 3.5。 The problem is that when I call the COM exposed method in the C# DLL I get an error returned saying "Could not find default endpoint..." 问题是,当我在C#DLL中调用COM公开的方法时,收到一条错误消息,提示“找不到默认端点...”。

This error seems to be because the service configuration is not being picked up, obviously because I have no app.config as this is purely a stand alone DLL. 该错误似乎是由于未获取服务配置,显然是因为我没有app.config,因为这纯粹是一个独立的DLL。 I could put the config in Excel.exe.config I'm sure but that isn't an option as making changes to users Excel configuration will not be allowed. 我可以确定可以将配置放在Excel.exe.config中,但这不是一个选择,因为不允许更改用户的Excel配置。 And I cannot hard code values into the C# code as we will need different environments configurable with an external config file. 而且我无法将值硬编码到C#代码中,因为我们将需要使用外部配置文件配置的不同环境。

Basically I need to have a config file that I can distribute with my DLL and the excel add in, so that when excel calls my COM exposed C# DLL, it then also picks up the Config file and loads the WCF endpoint configuration from there. 基本上,我需要有一个配置文件,该文件可以随我的DLL和excel加载项一起分发,以便当excel调用我的COM公开的C#DLL时,它也将拾取配置文件并从那里加载WCF终结点配置。 I know how to read a config file in using ConfigurationManager but I cannot figure out how to let .NET know that this config file contains the EndPoint information for the WCF services. 我知道如何使用ConfigurationManager读取配置文件,但无法弄清楚如何让.NET知道此配置文件包含WCF服务的EndPoint信息。 The only solution I have found so far involves overriding the default app domain configuration loading so that .NET loads your manually specified file for app.config default settings, but all the solutions I have foudn for this online use .NET 4.5 objects and code, when I am limited to .NET 3.5. 到目前为止,我发现的唯一解决方案是覆盖默认的应用程序域配置加载,以便.NET加载您为app.config默认设置手动指定的文件,但是我为此在线提供的所有解决方案都使用.NET 4.5对象和代码,当我仅限于.NET 3.5时。

Can anyone help me with this? 谁能帮我这个?

You should consider confugurating your WCF client endpoint in the code rather than in config file. 您应该考虑在代码中而不是在配置文件中配置WCF客户端终结点。 For more details please see: 有关更多详细信息,请参见:

http://msdn.microsoft.com/en-us/library/ff647110.aspx http://msdn.microsoft.com/en-us/library/ff647110.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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