關於webService提示An endpoint configuration…的問題

來源:互聯網
上載者:User

在silverlight中使用webService如果你兩次以上刪除同一個服務同時再添加該服務的情況下,程式在調試階段會報錯。錯誤提示為:

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

因為之前沒接觸過WSDL檔案,對於WSDL檔案報錯還是有點束手無策。我就直接複製這個錯誤到google中搜尋,後來發現搜尋結果都是WCF的樣式,還是看不懂。一段時間後我再次讀這個錯誤,這個錯誤說 

because more than one endpoint configuration for that contract was found

代表有多個終結點存在,需要顯示指定使用哪個。再參考WCF中的解決方案(在此不羅列)於是我找到webService中的設定檔(注意是設定檔.svcinfo為尾碼,而不是WSDL檔案)webService在vs中顯示的樣式如

       

查看該設定檔如下

 <?xml version="1.0" encoding="utf-8"?><configurationSnapshot xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:schemas-microsoft-com:xml-wcfconfigurationsnapshot">  <behaviors />  <bindings>    <binding digest="System.ServiceModel.Configuration.BasicHttpBindingElement, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089:<?xml version="1.0" encoding="utf-16"?><Data maxBufferSize="2147483647" name="CompareChartServiceSoap11Binding5"><security mode="None" /></Data>" bindingType="basicHttpBinding" name="CompareChartServiceSoap11Binding5" />  </bindings>  <endpoints>    <endpoint normalizedDigest="<?xml version="1.0" encoding="utf-16"?><Data address="http://localhost:8080/axis2/services/CompareChartService" binding="basicHttpBinding" bindingConfiguration="CompareChartServiceSoap11Binding5" contract="CompareChartService.CompareChartServicePortType" name="CompareChartServiceHttpSoap11Endpoint5" />" digest="<?xml version="1.0" encoding="utf-16"?><Data address="http://localhost:8080/axis2/services/CompareChartService" binding="basicHttpBinding" bindingConfiguration="CompareChartServiceSoap11Binding5" contract="CompareChartService.CompareChartServicePortType" name="CompareChartServiceHttpSoap11Endpoint5" />" contractName="CompareChartService.CompareChartServicePortType" name="CompareChartServiceHttpSoap11Endpoint5" />  </endpoints></configurationSnapshot>

這個檔案是沒問題的,要解決該錯誤就得在原來聲明終結點的時給建構函式指定一個參數

原來使用的是預設建構函式

ServiceEndpoint ep = new PAS.I1Service.CompareChartService.CompareChartServicePortTypeClient().Endpoint;

現在則在建構函式中明確endpoint的名稱

ServiceEndpoint ep = new PAS.I1Service.CompareChartService.CompareChartServicePortTypeClient("CompareChartServiceHttpSoap11Endpoint5").Endpoint;

從此次錯誤中發現,很多新錯誤確實從來都沒接觸過,此時不要急於地去搜尋解決方案,而是先完全理解錯誤是什麼。這樣解決錯誤的效率就會高一些!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.