Skip to main content

Posts

Showing posts from October, 2012

How to read incoming and outgoing message in wcf

In this post,I will show you how to read outgoing and incoming message in wcf.Create a new console application and add following assembly reference in the projectusing System.ServiceModel; using System.ServiceModel.Description;and paste following codeusing System; using System.Collections.Generic; using System.Linq; using System.Text; using System.ServiceModel; using System.ServiceModel.Description; namespace WCF_MessageInspector { [ServiceContract] publicinterface IHelloService { [OperationContract] string Greet(string name); } [ConsoleServiceBehavior] [ServiceBehavior] publicclass HelloService : IHelloService { publicstring Greet(string name) { return"Hello ," + name; } } class Program { staticvoid Main(string[] args) { string baseUrl = "http://localhost:12345"; ServiceHost host = new ServiceHost(typeof(HelloService), new Uri(b…

How to read namespace based xml using Linq

In this post,I will show you how to read xml with namespace.For this demo,I will use following xmlstructure<?xml version="1.0" encoding="utf-8" ?> <accounts xmlns="urn:account"> <account>1001</account> <account>1002</account> </accounts> using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml.Linq; namespace XLinq { class Program { static void Main(string[] args) { var doc = XDocument.Load("accounts.xml"); var query = from x in doc.Descendants("{urn:account}account") select x; foreach (var item in query) { Console.WriteLine(item); } } } }