Excel插件不加载的app.config与服务引用配置信息 [英] Excel Add-In not loading app.config with service reference config information

查看:1178
本文介绍了Excel插件不加载的app.config与服务引用配置信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写一个应用程序与服务的参考,使Web服务调用到特定的URL,它的伟大工程。我想这code移动到一个Excel插件,但我碰到这个问题:

I've written an app with a service reference to make web services calls to a specific URL and it works great. I want to move this code into an Excel Add-In, but I run into this problem:

未处理的异常信息:未能与在ServiceModel客户端配置节名'ConnectivityHttpsSoap12Endpoint和合同Connectivity.ConnectivityPortType找到终结点元素。这可能是因为没有配置文件,发现你的应用程序,或者是因为匹配该名称的终结点元素可以在客户端的元素被发现。

Unhandled Exception Message: Could not find endpoint element with name 'ConnectivityHttpsSoap12Endpoint' and contract 'Connectivity.ConnectivityPortType' 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.

问题是,我的app.config(W /服务参考信息)没有被加载,因为Excel正在叫我的类库,并调用应用程序的app.config中需要有服务引用添加到它。但这样的可以用Excel做了什么?更妙的是,有没有办法只加载从code我的app.config?

The problem is that my app.config (w/the service reference info) isn't being loaded because Excel is calling my class library, and the app.config of the calling application would need to have the service reference added to it. But can that be done with Excel? Better yet, is there a way to just load my app.config from code?

推荐答案

您需要使用 ConfigurationManager中来打开它。您可以在调用程序集路径(通常)您的app.config文件,所以你可以写这样的方法:

You would need to open it using the ConfigurationManager. You can find your app.config file in the calling assembly path (usually), so you could write a method like this:

public static Configuration LoadLocalConfigurationFile(string fileName)
{
    // fileName is the configuration file you want to open
    var configMap = new ExeConfigurationFileMap 
    { 
        ExeConfigFilename = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, fileName)
    };

    return ConfigurationManager.OpenMappedExeConfiguration(
        configMap, ConfigurationUserLevel.None);
}

这篇关于Excel插件不加载的app.config与服务引用配置信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆