2012-03-07 39 views
6

所以已經有幾天瞭解我的項目中的Web引用,現在我遇到了一個奇怪的問題。使用網絡參考

使用一個簡單的控制檯應用程序我這樣做:

namespace Webservices09004961 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 

      { 
       Convert.ConvertTemperatureSoapClient client = 
       new Convert.ConvertTemperatureSoapClient(); 
       while (true) 
       { 
        Console.Write("Enter temperature in Celsius: "); 
        double tempC = double.Parse(Console.ReadLine()); 
        double tempF = client.ConvertTemp(tempC, Convert.TemperatureUnit.degreeCelsius, Convert.TemperatureUnit.degreeFahrenheit); 
        Console.WriteLine("That is " + tempF + " degrees Farenheit"); 
       } 
      } 
     } 
    } 
} 

我在服務引用「轉換」與此相關的鏈接添加: http://www.webservicex.net/ConvertTemperature.asmx?WSDL

但是我得到這個錯誤:

An endpoint configuration section for contract 'Convert.ConvertTemperatureSoap' could not be loaded because more than one endpoint configuration for that contract was found. Please indicate the preferred endpoint configuration section by name.

這是因爲你只能分配一個服務引用在任何一個 時間?我問的原因是因爲我在同一個項目構建中的本地服務引用仍然正常工作?但是這個不? (它當我第一次創建它時)

或者這是一個單獨的問題?

還有什麼是對SOAP的限制?

+2

答案將在你的.config文件中。 – 2012-03-07 17:13:10

+0

是的,我找到了。無論如何謝謝 – 2012-03-07 17:20:04

回答

10

當您嘗試刪除svc引用並再次添加它時,此錯誤很常見。檢查你的app/web.config文件,你應該有Convert.ConvertTemperatureSoap的重複條目。刪除其中的一個,它會正常工作。

+1

感謝評論Davita我發現它:) – 2012-03-07 17:20:24

+0

不客氣:) – Davita 2012-03-07 17:20:57

+1

大聲笑這個答案救了我兩次! – Pomster 2013-02-07 10:30:33

0
 <endpoint address="http://www.webservicex.net/ConvertTemperature.asmx" 
      binding="basicHttpBinding" bindingConfiguration="ConvertTemperatureSoap" 
      contract="Convert.ConvertTemperatureSoap" name="ConvertTemperatureSoap" /> 
     <!--<endpoint address="http://www.webservicex.net/ConvertTemperature.asmx" 
      binding="customBinding" bindingConfiguration="ConvertTemperatureSoap12" 
      contract="Convert.ConvertTemperatureSoap" name="ConvertTemperatureSoap12" />--> 

它確定我發現錯誤與我的配置文件中的一個雙項有關。奇怪的不知道它爲什麼這樣做。

現在就開始工作。