【发布时间】:2010-12-07 15:27:08
【问题描述】:
我有一个调用外部 Web 服务的 DLL(vs2008 中的库项目)。项目具有对外部 Web 服务的服务引用
我在单元测试项目中有单元测试和app.config(带有servicemodel配置),一切正常。
现在,我使用 Addin VS 2008,并且没有像 Windows Forms 或 Asp.net 这样的配置文件。 插件是一个dll,它有配置文件。
如果我使用 WCF(使用我的项目 DLL),则找不到配置 system.servicemodel
我看过这个: http://vassiltonev.blogspot.com/2009/03/loading-custom-config-file-instead-of.html
但添加自定义 wcf 行为扩展会导致 ConfigurationErrorsException
无法加载为扩展“customTextMessageEncoding”注册的类型“Microsoft.ServiceModel.Samples.CustomTextMessageEncodingElement, CalidadCodigo.Integracion.CustomTextEncoder”。 (E:\TFS\pro\AddIn\bin\Debug\MyAddIn.dll.config 第 123 行
我在我的扩展 WCF 中使用 Assembly QualifiedName 进行测试但错误。
还有其他建议或示例代码吗?
我的配置
<extensions>
<bindingElementExtensions>
<add name="customTextMessageEncoding"
type="Microsoft.ServiceModel.Samples.CustomTextMessageEncodingElement,CalidadCodigo.Integracion.CustomTextEncoder, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</bindingElementExtensions>
</extensions>
代码
internal static WebServicePortTypeClient CrearClienteWCF()
{
try
{
return new WebServicePortTypeClient();
}
catch (Exception ex)
{
//TODO: not found serviceModel config
var addInConfig = System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Reflection.Assembly.GetExecutingAssembly().Location);
var endpointAddress = addInConfig.AppSettings.Settings[EasyVistaSvcEndPointAddress].Value;
var endpoint = new System.ServiceModel.EndpointAddress(endpointAddress);
return new WebServicePortTypeClient(EndPointConfigurationName, endpoint);
// The type 'Microsoft.ServiceModel.Samples.CustomTextMessageEncodingElement, CalidadCodigo.Integracion.CustomTextEncoder' registered for extension 'customTextMessageEncoding' could not be loaded. (E:\TFS\pro\AddIn\bin\Debug\MyAddIn.dll.config line 123)
}
}
【问题讨论】:
标签: c# visual-studio-2008 wcf add-in configuration-files