Create client to test WCF Rest Service

Please refer to the WCF Rest Service we created in the earlier post

<<earlier post link>>

Here we’d call the GetDatUsingDataContract operation which accepts a CompositeType

In the previous example we should set the the NameSpace for the DataContract. Here we are setting it to be blank.

Using Web Request

WebRequest req = WebRequest.Create(@”http://localhost:64538/Service1.svc/getdatacontract&#8221;);

req.Method = “POST”;

req.ContentType = @”application/xml; charset=utf-8″;

StringBuilder builder = new



builder.AppendLine(“<StringValue>test string</StringValue>”);


req.ContentLength = Encoding.UTF8.GetByteCount(builder.ToString());

using (Stream stream = req.GetRequestStream())


stream.Write(Encoding.UTF8.GetBytes(builder.ToString()), 0, Encoding.UTF8.GetByteCount(builder.ToString()));


HttpWebResponse resp = req.GetResponse() as

MessageBox.Show(string.Format(“Status Code: {0}, Status Description: {1}, resp.StatusCode,


Using WebChannelFactory

Add reference to the following assemblies in the Client Application

è WCF Project Assembly. (Here basically all we need is the contract – ServiceContract and DataContract class used by the WCF Service i.e. IService1 class)

Source Code:

WebChannelFactory<IService1> webChannelFactory = new


IService1 client = webChannelFactory.CreateChannel();

CompositeType compositeType = new

compositeType.BoolValue = true;

compositeType.StringValue = “Test String”;

CompositeType resCompositeType = client.GetDataUsingDataContract(compositeType);

Hope it helps.


Debugging WCF Rest Service


Here we will see how we can debug a WCF Rest Service using Advanced Rest Client (Chrome Extensions)

Suppose this is our sample WCF Rest Service we want to debug

(Please check the following post on details of creating a WCF rest service <<earlier posts link>>)

The Advanced Rest Client interface

  • Here we have specified Url of the Rest Service
  • The Post Data to be passed
  • The response that we got back

Now to debug our WCF Rest Service set the debugging point and attach the debugger to the Advanced Rest Client process.


Run the WCF Service in the Visual Studio.

Specify the WCF Rest Service URL and Post Data expected and then click on Send on the Advanced Rest Client.

The debugging will start

Hope it helps.