簡體   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