2010-06-04 74 views
0

我在引用合同組件的服務解決方案中創建了代理庫類,並將庫(Contract,Proxy)複製到另一個解決方案文件夾。然後在另一個類庫中引用Proxy,Contract和System.ServiceModel庫,我需要使用包含的一個方法,以及在庫中添加一個App.Config。在WCF客戶端中找不到默認端點元素...

該服務託管在Windows窗體應用程序中。客戶端是一個從Windows窗體應用程序調用的類庫。我還沒有在Windows窗體項目中創建一個App.Config。事實上,Windows Form項目會在庫中加載控件,並且控件會加載需要使用服務方法的庫。所以我認爲我應該只參考最新的裝配中的(合同和代理),因爲我不會在其他任何地方使用它。

,但我不斷收到此錯誤:

Could not find default endpoint element that references contract 'Sign.Contracts.ISignDocument' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.

App.Config中在libray調用代理:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <system.serviceModel> 
    <services> 
     <client> 
     <endpoint 
      address="http://localhost:8731/SignHere" 
      binding="basicHttpBinding" 
      contract="Sign.Contracts.ISignDocument" /> 
     </client> 
    </services> 
    </system.serviceModel> 
</configuration> 

App.Config中服役主持人:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <system.serviceModel> 
    <services> 
     <service name="Sign.Service.SignDocumentService"> 
     <endpoint 
      address="http://localhost:8731/SignHere" 
      binding="basicHttpBinding" 
      contract="Sign.Contracts.ISignDocument" /> 
     </service> 
    </services> 
    </system.serviceModel> 
</configuration> 

代理等級:

namespace Sign.Proxies 
{ 
    public class Proxy : ClientBase<ISignDocument>, ISignDocument 
    { 
     public string SignDocument(string document) 
     { 
      return Channel.SignDocument(document); 
     } 
    } 
} 

合同類:

namespace Sign.Contracts 
{ 
    [ServiceContract] 
    public interface ISignDocument 
    { 
     [OperationContract] 
     string SignDocument(string document); 
    } 
} 

任何想法?

+1

要格式化代碼或XML,請在編輯器中選擇它並按下Control-K。 – 2010-06-04 01:17:41

回答

1

任何程序只有一個配置文件。在你的情況下,這是Winforms程序的app.config,當程序被構建時它將被複制到programName.exe.config。

任何WCF配置必須在該文件中。事實上,你的庫有一個app.config並不重要。您需要從庫的app.config中複製相關配置條目,並將它們與Winforms應用程序的app.config合併。

+0

在winform項目中添加了一個App.Config文件,我得到了同樣的錯誤。 – AlwaysBeCoding 2010-06-04 01:33:33

+0

這不是問題。您需要將WCF配置從庫的app.config複製到Winforms應用程序的app.config中。 – 2010-06-04 01:37:22

+0

是的,抱歉,我的意思是,我在winforms應用程序中創建了一個App.Config文件並複製了內容。 – AlwaysBeCoding 2010-06-04 01:40:16

1

doooh ...客戶端app.config中沒有用於客戶端端點信息的父元素。

相關問題