2010-12-07 17 views
0

私は外部Webサービスを呼び出すDLL(vs2008のライブラリプロジェクト)を持っています。プロジェクトは外部Webサービスへのサービス参照を持っていますConfigurationErrorsException Addin VS2008用のWCF serviceModelを使用

私は単体テストを持っていて、単体テストプロジェクトではapp.config(servicemodel構成で)があります。

今、私はAddin VS 2008を使用し、WindowsフォームやAsp.netのような設定ファイルを持っていません。 addinはdllであり、configファイルを持っています。 http://vassiltonev.blogspot.com/2009/03/loading-custom-config-file-instead-of.html

が、カスタムWCFの動作拡張を追加するConfigurationErrorsException

原因:私は(私のプロジェクトのDLLを使用して)WCFを使用している場合

は、設定は私がこれを見てきました

が見つかりませんsystem.servicemodel

拡張子 'customTextMessageEncoding'に登録された 'Microsoft.ServiceModel.Samples.CustomTextMessageEncodingElement、CalidadCodigo.Integracion.CustomTextEncoder'を読み込めませんでした。 (E:\ TFS \プロ\アドイン\ binに\デバッグ\ MyAddIn.dll.configライン123

私は私の拡張WCFでアセンブリ修飾名でテストが、間違った

任意のより多くの提案や任意のサンプルコード。 ?

私の設定

<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) 


       } 
      } 

答えて

1

AFAIK DLLでConfigurationManagerを使用できません。私はVS2010用のプラグインを書いている間、同じ問題で走った。

私の解決策は、ファイルから設定をロードAN、このようなコードに自分でエンドポイントとendpointadressを作成することでした。

Uri myUri = loadUriFromFile(); 

var endpoint = new EndpointAddress(myUri); 

NetTcpBinding binding = GetNewTcpBindingFromFile(); 

return new WebServicePortTypeClient(binding, endpoint); 
+0

私はプログラム的にCustomBindingと拡張機能を作成するにはどうすればよいです? – Kiquenet

+0

wcfサービスのapp.configでVisual Studioが生成するXMLコードを見ることができます。これは、シリアル化されたオブジェクトは、あなたが満たす必要があるプロパティを見て簡単です。 – Kolja

関連する問題