2011-01-19 45 views
4

我創建了一個Web服務,爲此我嘗試爲3個端點提供不同的綁定。 1. basicHttpBinding的, 2的wsHttpBinding, 3的WebHttpBindingWebHttpBinding未到達客戶端

當我做了服務的參考,我只得到創建與basicHttpBinding的端點和綁定的wsHttpBinding。我沒有得到webHttpBinding。可能有什麼錯誤。

下面是web.config中serviceModel節點的結構。

<system.serviceModel> 
<diagnostics> 
    <messageLogging logEntireMessage="true" logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true"/> 
</diagnostics> 
<services> 
    <service behaviorConfiguration="VersionTolerance.Service1Behavior" name="BookShop.BookShopService"> 
    <endpoint address="sadha" binding="basicHttpBinding" contract="BookShop.IBookShopService" /> 
    <endpoint address="ws" binding="wsHttpBinding" contract="BookShop.IBookShopService" > 
    </endpoint> 
    <endpoint address="web" binding="webHttpBinding" behaviorConfiguration="webHttpBehavior" 
     contract="BookShop.IBookShopService" /> 
    <host> 
     <baseAddresses> 
     <add baseAddress="http://localhost:49654/" /> 
     </baseAddresses> 
    </host> 
    </service> 
</services> 
<behaviors> 
    <serviceBehaviors> 
    <behavior name="VersionTolerance.Service1Behavior"> 
     <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --> 
     <serviceMetadata httpGetEnabled="true"/> 
     <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --> 
     <serviceDebug includeExceptionDetailInFaults="false"/>   
    </behavior> 
    </serviceBehaviors> 
    <endpointBehaviors> 
    <behavior name="webHttpBehavior"> 
     <webHttp/> 
    </behavior> 
    </endpointBehaviors> 
</behaviors> 

回答

10

這沒有什麼錯 - 這只是它的工作方式!

basicHttpBindingwsHttpBinding是SOAP綁定,揭露他們的服務元數據 - 您的Visual Studio Add Service Reference可以詢問他們的終點,找出他們叫什麼,他們提供什麼樣的方法,什麼樣的數據類型,他們希望作爲參數和返回值是什麼。

webHttpBinding是REST - 和REST在默認情況下沒有元數據的概念 - 你不會得到一個服務描述,方法等列表 - REST是所有關於資源 - 不是方法。

因此,當您執行Add Service Reference時,您會獲得SOAP端點的代理客戶端 - 但對於REST/webHttpBinding端點,而不是。按設計工作。

構建在REST之上的WCF數據服務爲SOAP綁定提供了類似的體驗,因爲您可以執行一個Add Service Reference並獲得一個很好的客戶端代理和全部 - 而且這是自OData協議定義一個在REST之上的元數據交換。所以如果你可以把你的REST服務變成一個WCF數據服務,你會再好的。否則,使用REST,您只需從文檔頁面或其他內容中「知道」REST服務的資源URI是什麼,以及HTTP動詞在您的REST環境中執行了什麼操作。

+0

謝謝@marc_s,我想同意你的回答。但我想通過創建一個客戶端來體驗webHttpBinding。 用外行人的話說,我應該怎麼做才能在Visual Studio中爲這個服務創建一個代理並開始使用它? – SaravananArumugam 2011-01-19 18:01:26