简体   繁体   中英

ConfigurationErrorsException using WCF serviceModel for Addin VS2008

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)


                }
            }

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:

Uri myUri = loadUriFromFile();

var endpoint = new EndpointAddress(myUri); 

NetTcpBinding binding = GetNewTcpBindingFromFile(); 

return new WebServicePortTypeClient(binding, endpoint);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM