Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ConfigurationErrorsException使用用于加载项VS2008的WCF serviceModel_C#_Visual Studio 2008_Wcf_Add In_Configuration Files - Fatal编程技术网

C# ConfigurationErrorsException使用用于加载项VS2008的WCF serviceModel

C# ConfigurationErrorsException使用用于加载项VS2008的WCF serviceModel,c#,visual-studio-2008,wcf,add-in,configuration-files,C#,Visual Studio 2008,Wcf,Add In,Configuration Files,我有一个DLL(vs2008中的库项目),它调用外部web服务。项目具有对外部webservice的服务引用 我在单元测试项目中有单元测试和app.config(带有servicemodel配置),一切正常 现在,我使用的是Addin VS 2008,并且具有Windows窗体或Asp.net之类的nt配置文件。 加载项是一个dll,它具有配置文件 如果使用WCF(使用我的项目DLL),则找不到config system.servicemodel 我看到了这一点: 但是添加自定义wcf行为扩展

我有一个DLL(vs2008中的库项目),它调用外部web服务。项目具有对外部webservice的服务引用

我在单元测试项目中有单元测试和app.config(带有servicemodel配置),一切正常

现在,我使用的是Addin VS 2008,并且具有Windows窗体或Asp.net之类的nt配置文件。 加载项是一个dll,它具有配置文件

如果使用WCF(使用我的项目DLL),则找不到config system.servicemodel

我看到了这一点:

但是添加自定义wcf行为扩展会导致
ConfigurationErrorsException

无法加载为扩展名“customTextMessageEncoding”注册的类型“Microsoft.ServiceModel.Samples.CustomTextMessageEncodingElement、CalidadCodigo.Integration.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>

恐怕在DLL中使用ConfigurationManager是不可能的。我在为VS2010编写插件时也遇到过同样的问题

我的解决方案是从文件中加载设置,然后自己在代码中创建端点和端点地址,如下所示:

Uri myUri = loadUriFromFile();

var endpoint = new EndpointAddress(myUri); 

NetTcpBinding binding = GetNewTcpBindingFromFile(); 

return new WebServicePortTypeClient(binding, endpoint);

如何以编程方式创建CustomBinding和extensions?您可以查看visual studio在app.config中为wcf服务生成的xml代码。该序列化对象很容易查看您必须填充的属性。
Uri myUri = loadUriFromFile();

var endpoint = new EndpointAddress(myUri); 

NetTcpBinding binding = GetNewTcpBindingFromFile(); 

return new WebServicePortTypeClient(binding, endpoint);