3.2 Example 2 (WCF): Hello World

This code example illustrates a simple request and response that is mapped to the Consume a Web Service use case. The service defines the following service contract.

 [ServiceContract]
 public interface IHelloWorldService
 {
     [OperationContract]
     string SayHello(string name);
 }

The server implementation returns the string "Hello World!!" when the client sends the sayHello message with "World!!" as its input argument.

 public class HelloWorldService : IHelloWorldService
 {
     public string SayHello(string name)
     {
         return string.Format("Hello, {0}", name);
     }
 }

This code example uses basicHttpbinding, which uses SOAP over HTTP.

 <endpoint address="http: //localhost: 80/QuickReturns/Exchange"
                    bindingsSectionName="BasicHttpBinding"
                    contract="IHelloWorldService" />