Posts

Showing posts from November, 2017

Hosting a WCF Service in IIS / C#

Image
Step 1: Create a new Visual Studio project Choose the WCF installed template and create a new WCF Service Application: Step 2: Create your web service code Update the IService1.cs and Service1.svc.cs classes that are automatically created. You can of course delete these and create your own but I am re-using here for the sake of brevity. For ease of demonstration I will create an extremely simple “Hello world!” example. IService1.cs [code language="csharp"] using System.ServiceModel; using System.ServiceModel.Web; namespace WcfService { [ServiceContract] public interface IService1 { [OperationContract] [WebGet(UriTemplate = "/HelloWorld/")] string HelloWorld(); } } [/code] Service1.svc.cs [code language="csharp"] namespace WcfService { public class Service1 : IService1 { public string HelloWorld() { return "Hello world!"; } } } [/code] Re-build the visu...

Creating and consuming a web service in WCF

Image
Creating the WCF web service in Visual Studio In this post I am using the WCF Web Service as an example, see this post for an example using using asmx: https://www.technical-recipes.com/2017/creating-and-consuming-a-web-service-in-c-net/ A useful C# Corner post: http://www.c-sharpcorner.com/article/create-wcf-web-service-in-visual-studio-2015/ Create a new Visual Studio project In Visual Studio select the WCF installed template and create a new WCF Service Application: Observe that a number of files are automatically created: IService1.cs, Service1.cs and Web.config, amongst others., We will modify the content of these for the purpose of this example: Update the code in IService.cs file, as highlighted below. Notice that is does not do much since I like to keep these recipes extremely simple, understanding the process is more important. IService1.cs [code language="csharp"] using System.Runtime.Serialization; using System.ServiceModel; using Sys...