2010-12-06 94 views
2

我正在創建一個web服務客戶端。我有這個問題 - 在MainWindow.xaml中有一條消息:'找不到名爲'LightsWSSoap'的端點元素,並在ServiceModel客戶端配置部分中籤訂'LightsWS.LightsWSSoap'。這可能是因爲沒有爲您的應用程序找到配置文件,或者因爲在客戶端元素中找不到匹配此名稱的端點元素。 在這個文件中我有這樣的:C#WebService端點問題

xmlns:vm="clr-namespace:LightsClient2.ViewModels" 
<Window.DataContext> 
    <vm:MainWindowViewModel /> 
</Window.DataContext> 

而在MainWindowViewModel web服務的構造函數用於:

LightsWSSoap lService = new LightsWSSoapClient("LightsWSSoap"); 

其中「LightsWS」是服務的名稱。

有一個app.config文件,並有enpoints定義它:

<client> 
     <endpoint address="http://xxx/Lights/LightsWS.asmx" 
      binding="basicHttpBinding" bindingConfiguration="LightsWSSoap" 
      contract="LightsWS.LightsWSSoap" name="LightsWSSoap" /> 
     <endpoint address="http://xxx/Lights/LightsWS.asmx" 
      binding="customBinding" bindingConfiguration="LightsWSSoap12" 
      contract="LightsWS.LightsWSSoap" name="LightsWSSoap12" /> 
    </client> 

有什麼不對?有任何想法嗎?

+0

`LightsWS.LightsWSSoap` - 接口? (應該是)如果是,那麼爲什麼不以I開頭(`LightsWS.ILightsWSSoap`)。您打算使用哪種類型的端點? basicHttpBinding還是customBinding? – 2010-12-06 21:55:22

回答

4

您需要在您的WPF應用程序的App.Config文件中配置您的客戶端端點。

如果還沒有App.Config文件,您可以通過向項目添加新項目並選擇「應用程序配置文件」來創建一個。

App.Config中的內容應該是這個樣子:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <system.serviceModel> 
    <client> 
     <endpoint binding="wsHttpBinding" contract="LightsWS.LightsWSSoap" name="LightsWSSoap" /> 
    </client> 
    </system.serviceModel> 
</configuration> 

還有很多更詳細的信息在MSDN上 - http://msdn.microsoft.com/en-us/library/ms731745%28VS.90%29.aspx

2

您應該添加app.config文件並定義您的端點。通常它是由Visual Studio創建的。但是,如果您在另一個程序集中創建了ServiceReference(例如,是單獨的dll),那麼只需將該程序集中的app.config複製到WpfApplication即可。