在 ServiceModel 客戶端配置部分中,找不到引用協定“ServiceReference1.IPathIdentifyService”的默認終結點元素

我的環境:VS2010 + C#(DLL) + WCF

即我使用C#編寫了一個DLL,在DLL裏面遠程調用WCF服務,然後EXE程序在調用DLL裏面的接口時,出現瞭如下錯誤:

System.InvalidOperationException: 在 ServiceModel 客戶端配置部分中,找不到引用協定“ServiceReference1.IPathIdentifyService”的默認終結點元素。這可能是因爲未找到應用程序的配置文件,或者是因爲客戶端元素中找不到與此協定匹配的終結點元素。
   在 System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors(ServiceEndpoint serviceEndpoint, String configurationName)
   在 System.ServiceModel.ChannelFactory.ApplyConfiguration(String configurationName, Configuration configuration)
   在 System.ServiceModel.ChannelFactory.ApplyConfiguration(String configurationName)
   在 System.ServiceModel.ChannelFactory.InitializeEndpoint(String configurationName, EndpointAddress address)
   在 System.ServiceModel.ChannelFactory`1..ctor(String endpointConfigurationName, EndpointAddress remoteAddress)
   在 System.ServiceModel.EndpointTrait`1.CreateSimplexFactory()
   在 System.ServiceModel.EndpointTrait`1.CreateChannelFactory()
   在 System.ServiceModel.ClientBase`1.CreateChannelFactoryRef(EndpointTrait`1 endpointTrait)
   在 System.ServiceModel.ClientBase`1.InitializeChannelFactoryRef()
   在 System.ServiceModel.ClientBase`1..ctor()

...

-------------------------------------------------------------------------------------------------------

解決方法:

調用WCF的類庫(即xxx.dll)會有一個app.config文件,把這個文件中的以下部分
<system.serviceModel>
省略
</system.serviceModel>


複製粘貼到主程序(EXE所在工程)的app.config文件中的<configuration></configuration>中。

-------------------------------------------------------------------------------------------------------------------------------

 

 

 

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章