如何在其他项目中包含Web参考端点配置

问题描述:

我有2个项目,X和Y. Y调用Web服务,配置在Y的app.config(它的一个DLL)中定义。如何在其他项目中包含Web参考端点配置

当XŸ调用方法,我得到以下异常:

System.InvalidOperationException: Could not find default endpoint element that references contract 'xxxx.ServiceSoap' 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. 

我怎么能包括/导入个Y的app.config到X的web.config所以它都会有这样的配置呢?

谢谢!

您不能将一个项目的配置文件包含到另一个项目中。

你可以做的是使X项目中的新的配置文件(即只有配置为Web服务),然后包括配置文件到您的X.

例如主要的web.config。

比方说你犯了一个新的配置文件名称为“Endponts.config”

它看起来像

<endpoints> 
...... 
</endpoints> 

然后你就可以在你的主web.config文件中使用此Endpoints.config文件

<system.web> 
    ... 
    <endpoints configSource="Endponts.config" /> 
    ... 
    </system.web> 
+0

你确定它应该住在? – Himberjack 2011-05-30 10:24:22

+0

它取决于您要导入的设置,标准Web设置进入,现在您的案例是端点(您充当客户端),那么它将进入/。 – Sumit 2011-05-30 10:51:39