How do I write a contract for a wrapped message in the default namespace?
I've written a quick sample to demonstrate what happens when you write the contract without taking any namespaces into account.
[ServiceContract]public interface IService{ [OperationContract] [WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "/")] void ProcessRequest(string data);}public class Service : IService{ public void ProcessRequest(string data) { Console.WriteLine(OperationContext.Current.RequestContext.RequestMessage); }}class Program{ static void Main(string[] args) { string address = "http://localhost:8000/"; WebServiceHost host = new WebServiceHost(typeof(Service), new Uri(address)); host.Open(); ChannelFactory<IService> factory = new ChannelFactory<IService>(new WebHttpBinding()); factory.Open(); IService proxy = factory.CreateChannel(new EndpointAddress(address)); using (new OperationContextScope((IContextChannel)proxy)) { OperationContext.Current.OutgoingMessageHeaders.To = new Uri(address); proxy.ProcessRequest("data"); } factory.Close(); host.Close(); Console.ReadLine(); }}
Running the sample reveals that the message wrapper gets an unpleasant namespace instead of the default namespace.
<ProcessRequest xmlns="http://tempuri.org/"> <data>data</data></ProcessRequest>
By looking at the metadata, you could figure out where this namespace was coming from using the custom namespace sample I published earlier. In this case the problem is with the operation wrapper, which comes from the service contract. Setting the service contract to have a namespace of "" gets us the desired default namespace.
Next time: Using Faults with Untyped Messages