2011-09-20 39 views
4

我有一個提供兩個接口的Web服務。一個是「MyAppNameData」,另一個是「MyAppNameSync」。我將兩個服務引用添加到WPF應用程序。在代碼中,當我使用「MyAppNameData」引用時,我不會收到錯誤。當我使用產生「MyAppNameSync」以下錯誤:提供兩個接口的Web服務導致WPF應用程序出錯

Could not find default endpoint element that references contract 'MyAppNameSync.IMyAppNameSync' 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. 

我加了兩個引用的方式不盡相同,但是,使用帶有WsHttpBinding的加入basicHttpBinding的和MyAppNameSync加入MyAppNameData。我不知道爲什麼是這樣。

這是客戶端的app.config文件中的serviceModel元素。正如你所看到的,是引用了合同中的端點元素「MyAppNameSync.IMyAppNameSync」,違背了錯誤信息說什麼:

<system.serviceModel> 
    <bindings> 
     <basicHttpBinding> 
      <binding name="BasicHttpBinding_IMyAppNameData" 
       closeTimeout="00:01:00" 
       openTimeout="00:01:00" receiveTimeout="00:10:00" 
       sendTimeout="00:01:00" 
       allowCookies="false" bypassProxyOnLocal="false" 
       hostNameComparisonMode="StrongWildcard" 
       maxBufferSize="65536" maxBufferPoolSize="524288" 
       maxReceivedMessageSize="65536" 
       messageEncoding="Text" textEncoding="utf-8" 
       transferMode="Buffered" 
       useDefaultWebProxy="true"> 
       <readerQuotas maxDepth="32" maxStringContentLength="8192" 
       maxArrayLength="16384" 
        maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
       <security mode="None"> 
       <transport clientCredentialType="None" proxyCredentialType="None" 
         realm="" /> 
       <message clientCredentialType="UserName" algorithmSuite="Default" /> 
       </security> 
      </binding> 
     </basicHttpBinding> 
     <wsHttpBinding> 
      <binding name="WSHttpBinding_IMyAppNameSync" closeTimeout="00:01:00" 
       openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" 
       bypassProxyOnLocal="false" transactionFlow="false" 
       hostNameComparisonMode="StrongWildcard" 
       maxBufferPoolSize="524288" maxReceivedMessageSize="65536" 
       messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" 
       allowCookies="false"> 
       <readerQuotas maxDepth="32" maxStringContentLength="8192" 
       maxArrayLength="16384" 
        maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
       <reliableSession ordered="true" inactivityTimeout="00:10:00" 
        enabled="false" /> 
       <security mode="Message"> 
        <transport clientCredentialType="Windows" 
        proxyCredentialType="None" 
         realm="" /> 
        <message clientCredentialType="Windows" 
        negotiateServiceCredential="true" 
         algorithmSuite="Default" /> 
       </security> 
      </binding> 
     </wsHttpBinding> 
    </bindings> 
    <client> 
     <endpoint address="http://computername.domainname.home/MyAppNameSyncService/MyAppNameData.svc" 
      binding="basicHttpBinding" 
      bindingConfiguration="BasicHttpBinding_IMyAppNameData" 
      contract="MyAppNameData.IMyAppNameData" 
      name="BasicHttpBinding_IMyAppNameData" /> 
     <endpoint address="http://computername.domainname.home/MyAppNameSyncService/MyAppNameSync.svc" 
      binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IMyAppNameSync" 
      contract="MyAppNameSync.IMyAppNameSync" 
      name="WSHttpBinding_IMyAppNameSync"> 
      <identity> 
       <dns value="localhost" /> 
      </identity> 
     </endpoint> 
    </client>  
</system.serviceModel> 

任何建議將真正理解。

謝謝

+0

你是用同樣的方法添加兩個引用是什麼意思?你應該只需要添加一個引用,它應該創建兩個代理。 –

+0

感謝您的回覆。我發佈的Web服務中有兩個.svc文件。 MyAppNameData.svc和MyAppNameSync.svc。要添加服務引用,我右鍵單擊服務引用節點,選擇添加,其中一個svc文件,爲其命名空間名稱,然後單擊確定。我再次爲其他svc文件做同樣的事情。 – rogdawg

+0

好的,我很抱歉,我以爲你有兩個端點的單一服務,但你有兩個無關的服務。 –

回答

2

好的。我現在正在工作。我顯然在同一時間有幾個錯誤。正如雷切爾在她上面的評論中所建議的,我試圖找到一個最簡單的案例。但是,最初是無法。從主機中刪除一個服務,所以我只有MyAppNameData.svc沒有,最初,工作。我知道過去的web服務的簡單版本,所以我試圖讓所有的東西都回到那個工作點。

我用我的一個現有的ASP.NET Web應用程序指向我一直用於測試的Web服務的實例,並且我能夠讓它工作(即使有兩個服務; MyAppNameData。主機MyAppNameWebService中的svc和MyAppNameSync.svc)。所以,我知道問題出在我的WPF應用程序和Web服務之間。

我曾經看過幾個討論主題,聲明「如果您在類庫中調用該服務並從另一個項目調用該類庫,則會出現此錯誤」。但是,我認爲在解決問題的步驟中我已經解決了這個問題。但是,當我將WPF項目中的所有內容全部剝離並重建(第100次)時,確保「將WS配置設置包含在主項目app.config中,如果它的winapp或web.config網絡應用程序「,如 this thread中所述,我能夠得到它的工作!

我曾嘗試過這種解決方案,但顯然我還沒有解決一些其他問題。我不再收到錯誤,並且能夠連接並使用來自同一主機的兩個獨立服務。所以,我在做生意。

謝謝大家的回覆和建議。現在,迎接其他挑戰!

相關問題