VSTO 工作簿项目无法创建 Windows 服务代理类
我有一个 Excel VSTO 工作簿项目。 Excel工作簿使用Windows服务WCF连接。此连接是在 VSTO 工作簿模板项目中引用的另一个类库中定义的。
另一个项目使用以下代码启动此工作簿:
Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook wb = excel.Workbooks.Open(filepath);
excel.Visible = true;
然后,Excel 通过简单地创建新对象,在 Sheet_Activate 事件处理程序中创建一个 Windows 服务代理类:
MyServiceClient service = new MyServiceClient();
然后我得到一个异常:
“无法找到引用合同“MyService.xml”的默认端点元素。 IMyService' 在 ServiceModel 客户端配置部分中。这可能是因为没有为您的应用程序找到配置文件,或者因为在客户端元素中找不到与此合同匹配的端点元素。”。
但我收到此异常仅一台电脑。在少数其他电脑上,该应用程序运行良好。并且所有PC上的应用程序配置都是相同的:excel版本相同,Windows服务部署相同,app.config相同。我的应用程序因此错误而失败的原因可能是什么?
也许它真的找不到配置文件,如错误消息中所述?我该如何检查?我还能做什么来解决这个问题?
I have an Excel VSTO workbook project. The excel workbook uses windows service WCF connection. This connection is defined in another class library that is referenced in the VSTO workbook template project.
Another project launches this workbook using following code:
Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook wb = excel.Workbooks.Open(filepath);
excel.Visible = true;
Then excel creates a windows service proxy class in Sheet_Activate event handler by simply creating new object:
MyServiceClient service = new MyServiceClient();
And then I get an exception:
"Could not find default endpoint element that references contract 'MyService.IMyService' 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 contract could be found in the client element.".
But I get this exception on one PC only. On few other PCs this application works fine. And the app configuration is the same on all PCs: the excel version is the same, the windows service is deployed the same, the app.config is the same. What could be the reason of my application failing with this error?
Maybe it really can't find the config file, as said in error message? How do I check it? What else can I do to solve this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的工作簿似乎在工作簿不起作用的计算机上的 excel.exe.config 文件中查找配置。在工作簿工作的计算机上,会查找并找到“我的项目”.dll.config。我已将正确的配置文件复制到 Excel 应用程序目录作为“excel.exe.config”,现在一切正常。
It appears that my workbook looks for configuration in excel.exe.config file on the machine where the workbook doesn't work. On machines where workbook works "my project".dll.config is looked for and is found. I've copied the correct config file to excel application directory as "excel.exe.config" and everything works fine now.