Export (0) Print
Expand All

Step 6: Configure the WCF Client

Updated: June 18, 2014

This is the sixth of seven tasks required to create a basic Service Bus service and a client that calls the service. For an overview of all seven tasks, see Service Bus Relayed Messaging Tutorial. This topic describes how to create an App.config file for a basic client application that accesses the service created previously in this tutorial. This App.config file defines the contract, binding, and name of the endpoint. The code used for these tasks is provided in the example following the procedure.

Time to completion: 10 minutes

  1. noteNote
    Steps 1 and 2 are not necessary if you are using Visual Studio 2010 or later, because by default, the App.config file is already present in the project.

    Right-click the client project, select Add, New Item.

  2. In the Add New Item dialog, in the Templates pane, select Application Configuration File. Then click Add.

  3. In Solution Explorer, in the client project, double-click App.config to open the file, which currently contains the following XML elements:

    <?xml version="1.0"?>
    <configuration>
    <startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
    
  4. Add an XML element to the App.config file for system.serviceModel.

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <system.serviceModel>
        
      </system.serviceModel>
      
    </configuration>
    

    This element declares that your application uses WCF-style endpoints. As stated previously, much of the configuration of an Service Bus application is identical to a WCF application; the main difference is the location to which the configuration file points.

  5. Within the system.serviceModel element, add a <client> element.

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <system.serviceModel>
        <client>
          
        </client>
      </system.serviceModel>
    </configuration>
    

    This step declares that you are defining a WCF-style client application.

  6. Within the client element, define the name, contract, and binding type for the endpoint.

    <endpoint name="RelayEndpoint"
                    contract="Microsoft.ServiceBus.Samples.IEchoContract"
                    binding="netTcpRelayBinding"/>
    

    This step defines the name of the endpoint, the contract defined in the service, and the fact that the client application uses TCP to communicate with Service Bus. The endpoint name will be used in the next step, to link this endpoint configuration with the service URI.

  7. Directly after the <client> element, add the following binding extension:

    <extensions>
        <bindingExtensions>
          <add name="netTcpRelayBinding" type="Microsoft.ServiceBus.Configuration.NetTcpRelayBindingCollectionElement, Microsoft.ServiceBus, Version=1.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        </bindingExtensions>
    </extensions>
    
  8. Click File. Then click Save All.

Example

The following code sample shows the App.config file for the Echo client.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <client>
      <endpoint name="RelayEndpoint"
                      contract="Microsoft.ServiceBus.Samples.IEchoContract"
                      binding="netTcpRelayBinding"/>
    </client>
    <extensions>
      <bindingExtensions>
        <add name="netTcpRelayBinding" type="Microsoft.ServiceBus.Configuration.NetTcpRelayBindingCollectionElement, Microsoft.ServiceBus, Version=1.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
      </bindingExtensions>
    </extensions>
  </system.serviceModel>
</configuration>

Now that you have configured the client application, proceed to Step 7: Implement WCF Client to Call the Service Bus to implement the rest of the application.

Show:
© 2014 Microsoft