gpt4 book ai didi

c# - ExcelDNA : How to make a WCF configuration file available to my Excel AddIn?

转载 作者:太空宇宙 更新时间:2023-11-03 23:04:00 25 4
gpt4 key购买 nike

我正在尝试在 .XLL Excel 加载项的上下文中使用 WCF 服务。我正在使用由 ExcelDNA 库向 .NET 公开的 Excel 的 C-API。函数代码定义如下:

[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

关于c# - ExcelDNA : How to make a WCF configuration file available to my Excel AddIn?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42001210/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com