繁体   English   中英

ExcelDNA:如何使我的Excel AddIn可以使用WCF配置文件?

[英]ExcelDNA: How to make a WCF configuration file available to my Excel AddIn?

我正在尝试在.XLL Excel加载项的上下文中使用WCF服务。 我正在使用Excel的C-API作为ExcelDNA库暴露给.NET。 功能代码定义如下:

[ExcelFunction(Description = "Getting the WCF stack trace")]
public static string GetWCFStackTrace(string name)
{
    try
    {
        HTTPService.ExcelServiceClient client = new HTTPService.ExcelServiceClient("BasicHttpBinding_IExcelService");
        client.LogExcelRows("Hello World");
    }
    catch (Exception e)
    {
        Debug.WriteLine(e);
    }
    return "function complete";
}

这导致堆栈跟踪如下所示。 我已经测试了在加载项的执行上下文中我有权访问由服务引用生成的代理类(即typeof(HTTPService.ExcelServiceClient)在运行时正确返回)。

   Exception thrown: 'System.InvalidOperationException' in System.ServiceModel.dll
    System.InvalidOperationException: Could not find endpoint element with name 'BasicHttpBinding_IExcelService' and contract 'HTTPService.IExcelService' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this name could be found in the client element.
       at System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors(ServiceEndpoint serviceEndpoint, String configurationName)
       at System.ServiceModel.ChannelFactory.ApplyConfiguration(String configurationName, Configuration configuration)
       at System.ServiceModel.ChannelFactory.ApplyConfiguration(String configurationName)
       at System.ServiceModel.ChannelFactory.InitializeEndpoint(String configurationName, EndpointAddress address)
       at System.ServiceModel.ChannelFactory`1..ctor(String endpointConfigurationName, EndpointAddress remoteAddress)
       at System.ServiceModel.ConfigurationEndpointTrait`1.CreateSimplexFactory()
       at System.ServiceModel.ConfigurationEndpointTrait`1.CreateChannelFactory()
       at System.ServiceModel.ClientBase`1.CreateChannelFactoryRef(EndpointTrait`1 endpointTrait)
       at System.ServiceModel.ClientBase`1.InitializeChannelFactoryRef()
       at System.ServiceModel.ClientBase`1..ctor(String endpointConfigurationName)
       at ExcelDNATest.HTTPService.ExcelServiceClient..ctor(String endpointConfigurationName) in C:\Users\zach\Documents\Visual Studio 2015\Projects\ExcelDNATest\ExcelDNATest\Service References\HTTPService\Reference.cs:line 37
       at ExcelDNATest.TestFunctions.HelloDna(String name) in C:\Users\zach\Documents\Visual Studio 2015\Projects\ExcelDNATest\ExcelDNATest\TestFunction.cs:line 163

如何在ExcelDNA编译代码中包含端点配置?

===编辑

答案如下

输出目录中配置文件的名称需要与ExcelDNA创建的.XLL文件的名称相匹配。

例如

MyApp-AddIn.xll - > MyApp-AddIn.xll.config

MyApp-AddIn64.xll - > MyApp-AddIn64.xll.config

看着在谷歌网上论坛讨论这里 ,Excel的-DNA笔者提到的,我应该看到

... .config file in the output directory next to the .xll file ...

\\bin\\Debug\\目录中,我看到一个名为<slnName>.dll.config的文件,我将其重命名为<slnName>-AddIn.xll.config ,该服务现在按预期工作。 我想我也必须有一个<slnName>-AddIn64.xll.config文件。 但是会拭目以待。

顺便说一句,我想我在Google Group线程中看到提到配置文件没有被复制到输出文件夹。 但是,我发现配置文件WAS已复制到输出文件夹,我只需重命名它。 我还应该注意到我使用的是Excel-DNA v0.33.9

暂无
暂无

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

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