Posts

Showing posts from November, 2014

Simple Method to Test Rest Web Service

Image
private static string CallRestMethod(string url) { var webrequest = (HttpWebRequest)WebRequest.Create(url); webrequest.Method = "GET"; webrequest.ContentType = "application/x-www-form-urlencoded"; webrequest.Headers.Add("Username", "xyz"); webrequest.Headers.Add("Password", "abc"); var webresponse = (HttpWebResponse)webrequest.GetResponse(); Encoding enc = Encoding.GetEncoding("utf-8"); var responseStream = new StreamReader(webresponse.GetResponseStream(), enc); string result = responseStream.ReadToEnd(); webresponse.Close(); return result; }

Host WCF Service in IIS8

Image
Today I'm going to Show how to host a WCF Service in IIS in easy way. there are several approaches you can host WCF service to IIS. okay to host a service we need to create a Service right. so let's create a simple WCF Service. 1. Go to Visual Studio and create a new WCF Service Application Project.   2. Remove existing Methods from IService1 Interface and add below method to your project.     Note : You can add any other method rather than my one.       

How to Implement RESTful WCF Service

Image
Windows Communication Foundation (WCF) is an SDK for developing and deploying services on Windows. WCF provides a runtime environment for your services, enabling you to expose CLR types as services, and to consume other services as CLR types. In this article, I am going to explain how to implement restful service API using WCF 4.0 . The Created API returns XML and JSON data using WCF attributes. 1. What is REST (Representational state transfer)  In simple form  Representational state transfer (REST) is  another cool  architectural style. you can find more about the Restful architectural pattern here . 2. Why REST is famous these days. Less overhead (no SOAP envelope to wrap every call in) Less duplication (HTTP already represents operations like  DELETE ,  PUT ,  GET , etc. that have to otherwise be represented in a SOAP envelope). More standardized - HTTP operations are well understood and operate consistently. Some SOAP implementations ...

Custom SOAP Header for WCF Service

Image
From this article I'm going to explain how to create a custom SOAP header ( actually add custom attributes to the SOAP Header). So I hope you have some kind of knowledge regarding WCF. so I'm not going to explain fundamental thing in WCF. 1. Go to Visual Studio and create new WCF Service application 2. Then you can find Iservice1.cs Interface and Service1.svc file in your WCF project. so go to        Iservice interface and add a method call Method or even you can add whatever name you like. so  here is my one. [ServiceContract] public interface IService1 { [OperationContract] MyMessageResponse Method(MyMessage message); }