我正在尝试在.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编译代码中包含端点配置?
===编辑
答案如下:
答案 0 :(得分:2)
输出目录中配置文件的名称需要与ExcelDNA创建的.XLL文件的名称相匹配。
e.g。
MyApp-AddIn.xll
- > MyApp-AddIn.xll.config
MyApp-AddIn64.xll
- > MyApp-AddIn64.xll.config
答案 1 :(得分:1)
观看Google网上论坛HERE中的讨论,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 。