2012-07-12 57 views
1

我有非常具體的問題。 如果我創建一個WCF服務,並且它有多個端點名稱,如何使用瀏覽器訪問該端點? 另外我怎樣才能通過添加服務參考訪問我的客戶端應用程序?如何在服務參考中使用WCF服務如果它有多個端點名稱

像我的配置代碼:

<services> 
    <service name="MultipleEndpoint.SampleService" behaviorConfiguration="MultipleEndpoint.SampleService"> 
    <host> 
     <baseAddresses> 
     <add baseAddress="http://localhost:55052/SampleService.svc"/> 
     </baseAddresses> 
    </host> 
    <endpoint address="/basic" binding="basicHttpBinding" contract="MultipleEndpoint.ISampleService" bindingConfiguration="basicBinding" > 
    </endpoint> 
    <endpoint address="/wsHttp" binding="wsHttpBinding" contract="MultipleEndpoint.ISampleService" bindingConfiguration="wsBinding" >   
    </endpoint> 
    <endpoint address="/webHttp" binding="webHttpBinding" contract="MultipleEndpoint.ISampleService" behaviorConfiguration="REST"> 
    </endpoint>   
    </service> 
</services> 

現在,當我試圖訪問使用

http://localhost:55052/SampleService.svc/basic or 
http://localhost:55052/SampleService.svc/wsHttp 

它給了我沒有找到IE標準錯誤信息頁/資源... 同時我想知道如何將這種類型的url作爲服務引用添加到我的客戶端應用程序中?

回答

0

這些服務的地址是不同的,它們不是嚴格必須眉紫貂,意味着你不能瀏覽服務端點像的http://本地主機:55052/SampleService.svc /基本這些地址用於區分通信中的端點

如果您看到服務的wsdl,那麼在那裏指定那些端點的所有地址。

如果您創建服務,通過「添加服務引用」的所有端點在配置中創建單獨像代理..

<client> 
    <endpoint address="http://localhost:54671/Service1.svc/basic" 
      binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1" 
      contract="ServiceReference1.IService1" name="BasicHttpBinding_IService1" /> 

    <endpoint address="http://localhost:54671/Service1.svc/ws" binding="wsHttpBinding" 
      bindingConfiguration="WSHttpBinding_IService1" contract="ServiceReference1.IService1" 
      name="WSHttpBinding_IService1"> 
    </endpoint> 
    ... 
</client> 

說,如果你想使用基本的HTTP交談的服務端點,那麼您可以通過在ctor中傳遞相應的端點配置name來爲其創建代理。

Ex。

// this will uses the basic http endpoint. 
Service1Client client = new Service1Client("BasicHttpBinding_IService1");