using System.ServiceModel; var endpointAddress = new EndpointAddress("net.tcp://localhost:8080/MyService"); var binding = new NetTcpBinding(); var serviceChannel = new ChannelFactory(binding, endpointAddress); var serviceProxy = serviceChannel.CreateChannel(); // Call service methods serviceProxy.MyMethod();
using System.Net.Http; var client = new HttpClient(); client.BaseAddress = new Uri("http://api.example.com"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); // Call REST API endpoint HttpResponseMessage response = await client.GetAsync("/api/products"); if (response.IsSuccessStatusCode) { var products = await response.Content.ReadAsAsyncIn this example, we create an HTTP client that communicates with a REST API. We specify the base URL for the API and setup request headers to indicate that we want to receive data in JSON format. We then make an HTTP GET request to the API endpoint and deserialize the response into a list of Product objects. The package library for TransportType is included in the .NET Framework and can be accessed by adding a reference to System.ServiceModel or System.Net.Http libraries.>(); }