using System.ServiceModel; [ServiceContract] public interface IHelloWorldService { [OperationContract] string SayHello(string name); } public class HelloWorldService : IHelloWorldService { public string SayHello(string name) { return $"Hello, {name}!"; } }
using System.Web.Http; public class ProductsController : ApiController { public IHttpActionResult Get() { var products = new[] { new { Id = 1, Name = "Product 1", Price = 10.99 }, new { Id = 2, Name = "Product 2", Price = 19.99 }, new { Id = 3, Name = "Product 3", Price = 29.99 } }; return Ok(products); } }This code defines a controller class `ProductsController` that inherits from `ApiController`, which is a base class for Web API controllers. The `Get` method returns an `IHttpActionResult` object that wraps the JSON object containing the array of products. The `Ok` method is a helper method that creates an `OkResult` object with the specified content.