The Dual Http sample demonstrates how to configure the
WSDualHttpBinding binding. This sample consists of a client console program (.exe) and a service library (.dll) hosted by Internet Information Services (IIS). The service implements a duplex contract. The contract is defined by the
ICalculatorDuplex interface, which exposes math operations (Add, Subtract, Multiply, and Divide). In this sample, the
ICalculatorDuplex interface allows the client to perform math operations, calculating a running result over the session. Independently, the service returns results on the
ICalculatorDuplexCallback interface. A duplex contract requires a session, because a context must be established to correlate the set of messages being sent between client and service. The
WSDualHttpBinding binding supports duplex communication.
The setup procedure and build instructions for this sample are located at the end of this topic.
The samples may already be installed on your machine. Check for the following (default) directory before continuing.
If this directory does not exist, go to Windows Communication Foundation (WCF) and Windows Workflow Foundation (WF) Samples for .NET Framework 4 to download all Windows Communication Foundation (WCF) and WF samples. This sample is located in the following directory.
To configure a service endpoint with the
WSDualHttpBinding, specify the binding in the endpoint configuration as shown.
<endpoint address="" binding="wsDualHttpBinding" contract="Microsoft.ServiceModel.Samples.ICalculatorDuplex" />
On the client, you must configure an address that the server can use to connect to the client as shown in the following sample configuration.
<system.serviceModel> <client> <endpoint address= "http://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="http://localhost:8000/myClient/" useDefaultWebProxy="true" bypassProxyOnLocal="false"> </binding> </wsDualHttpBinding> </bindings> </system.serviceModel>
When you run the sample, the operation requests and responses are displayed in the client console window. Press ENTER in the client window to shut down the client.
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)
When you run the sample, you see the messages returned to the client on the callback interface sent from the service. Each intermediate result is displayed, followed by the entire equation upon completion of all operations. Press ENTER to shut down the client.
To set up, build, and run the sample
Install ASP.NET 4.0 using the following command.
%windir%\Microsoft.NET\Framework\v4.0.XXXXX\aspnet_regiis.exe /i /enable
Ensure that you have performed the One-Time Setup Procedure for the Windows Communication Foundation Samples.
To build the C# or Visual Basic .NET edition of the solution, follow the instructions in Building the Windows Communication Foundation Samples.
To run the sample in a single- or cross-machine configuration, follow the instructions in Running the Windows Communication Foundation Samples.
When running the client in a cross-machine configuration, be sure to replace localhost in both the
addressattribute of the endpoint element and the
clientBaseAddressattribute of the <binding> element of the <wsDualHttpBinding> element with the name of the appropriate machine, as shown:
<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>