WS 雙重 Http
雙重 Http 範例會示範如何設定 WSDualHttpBinding 繫結。這個範例是由用戶端主控台程式 (.exe) 和網際網路資訊服務 (IIS) 所裝載的服務程式庫 (.dll) 所組成。服務會實作雙工合約。合約是由 ICalculatorDuplex
介面所定義,這個介面會公開數學運算作業 (加、減、乘、除)。在此範例中,ICalculatorDuplex
介面允許用戶端執行數學運算,計算整個工作階段的執行結果。服務會獨立地傳回 ICalculatorDuplexCallback
介面上的結果。雙工合約需要一個工作階段,因為必須建立內容,將用戶端與服務之間傳送的訊息關聯在一起。WSDualHttpBinding 繫結支援雙工通訊。
注意: |
---|
此範例的安裝程序與建置指示位於本主題的結尾。 |
若要設定使用 WSDualHttpBinding 的服務端點,請在端點組態中指定此繫結,如下所示。
<endpoint address=""
binding="wsDualHttpBinding"
contract="Microsoft.ServiceModel.Samples.ICalculatorDuplex" />
在用戶端上,您必須設定伺服器可用來連接用戶端的位址,如下面的範例組態中所示。
<system.serviceModel>
<client>
<endpoint address=
"https://localhost/servicemodelsamples/service.svc"
binding="wsDualHttpBinding"
bindingConfiguration="Binding1"
contract="Microsoft.ServiceModel.Samples.ICalculatorDuplex" />
</client>
<bindings>
<!-- Configure a WSDualHttpBinding that supports duplex -->
<!-- communication. -->
<wsDualHttpBinding>
<binding name="Binding1"
clientBaseAddress="https://localhost:8000/myClient/"
useDefaultWebProxy="true"
bypassProxyOnLocal="false">
</binding>
</wsDualHttpBinding>
</bindings>
</system.serviceModel>
當您執行範例時,作業要求和回應會顯示在用戶端主控台視窗中。在用戶端視窗中按下 ENTER 鍵,即可關閉用戶端。
Press <ENTER> to terminate client once the output is displayed.
Result(100)
Result(50)
Result(882.5)
Result(441.25)
Equation(0 + 100 - 50 * 17.65 / 2 = 441.25)
當執行範例時,您會看到訊息在回呼服務所傳送的介面時傳回到用戶端。完成所有作業時,每個中繼結果都會顯示,並接著顯示整個方程式。按 ENTER 鍵關閉用戶端。
若要設定、建置及執行範例
若要建置方案的 C# 或 Visual Basic .NET 版本,請遵循建置 Windows Communication Foundation 範例中的指示。
若要在單一或跨電腦的組態中執行本範例,請遵循執行 Windows Communication Foundation 範例中的指示。
注意: 在跨電腦組態中執行用戶端時,請確定將endpoint項目的 address 屬性,以及 wsDualHttpBinding 項目之binding項目的 clientBaseAddress 屬性中的 localhost,都取代成適當電腦的名稱,如下所示: <client> <endpoint name = "" address= "http://service_machine_name/servicemodelsamples/service.svc" /> </client> ... <wsDualHttpBinding> <binding name="DuplexBinding" clientBaseAddress= "http://client_machine_name:8000/myClient/"> </binding> </wsDualHttpBinding>
Send comments about this topic to Microsoft.
© 2007 Microsoft Corporation. All rights reserved.