使用 Addin VS2008 的 WCF serviceModel 时出现 ConfigurationErrorsException
我有一个 DLL(vs2008 中的库项目),它调用外部 Web 服务。项目有一个对外部Web服务的服务引用
我有单元测试,并且单元测试项目中的app.config(带有服务模型配置),一切都正确。
现在,我使用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)
}
}
I have a DLL (library project in vs2008), that calls to external web service. Project has a Service reference to external webservice
I have Unit test, and app.config (with servicemodel configuration) in unit test project, and all is right.
Now, I use Addin VS 2008, and has'nt configuration file like Windows Forms or Asp.net.
the addin is a dll and it has config file.
If I use WCF (using my project DLL), the config system.servicemodel not found
I have seen this:
http://vassiltonev.blogspot.com/2009/03/loading-custom-config-file-instead-of.html
but Adding a custom wcf behavior extension causes a ConfigurationErrorsException
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
I test with Assembly QualifiedName in my extensions WCF but wrong.
any more suggestions or any sample code ?
my config
<extensions>
<bindingElementExtensions>
<add name="customTextMessageEncoding"
type="Microsoft.ServiceModel.Samples.CustomTextMessageEncodingElement,CalidadCodigo.Integracion.CustomTextEncoder, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</bindingElementExtensions>
</extensions>
The code
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)
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
AFAIK 不可能在 DLL 中使用 ConfigurationManager。我在为 VS2010 编写插件时遇到了同样的问题。
我的解决方案是从文件加载设置,然后在代码中自己创建端点和端点地址,如下所示:
AFAIK its not possible to use the ConfigurationManager in a DLL. I ran in the same issue while I wrote a Plugin for VS2010.
My Solution was to load the settings from a file an create the endpoint and endpointadress by myself in the code like this: