POX (Plain Old XML) support in Orcas is brilliant.
Consider the following service contract:
[ServiceContract(Namespace = "")]interface IPOXService{ [OperationContract] [HttpTransferContract(Path = "Echo", Method = "GET")] string Echo(string strString1, ref string strString2, out string strString3);}
And the following service (or, better Echo method) implementation:
public class POXService : IPOXService{ public string Echo(string strString1, ref string strString2, out string strString3) { strString2 = "strString2: " + strString2; strString3 = "strString3"; return "Echo: " + strString1; }}
Host it using this:
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();smb.HttpGetEnabled = true;ServiceHost sh = new ServiceHost(typeof(POXService), new Uri ("http://localhost:666"));ServiceEndpoint ep = sh.AddServiceEndpoint(typeof(IPOXService), new WebHttpBinding(), "POX");ep.Behaviors.Add(new HttpTransferEndpointBehavior());sh.Description.Behaviors.Add(smb);
sh.Open();Console.WriteLine("POX Service Running...");Console.ReadLine();sh.Close();
If you open IE and hit the service endpoint (http://localhost:666/POX/Echo) without URL encoded parameters, you get the following XML back:
<EchoResponse> <EchoResult>Echo:</EchoResult> <strString2>strString2:</strString2> <strString3>strString3</strString3> </EchoResponse>
Now, drop some parameters in (http://localhost:666/POX/Echo?strString1=boo&strString2=foo&strString3=bar), this is returned:
<EchoResponse> <EchoResult>Echo: boo</EchoResult> <strString2>strString2: foo</strString2> <strString3>strString3</strString3> </EchoResponse>
Nice. I especially like the fact that ref and out parameters are serialized with the metod return value.
Reach in with //EchoResponse/strString2 for ref parameter and //EchoResponse/strString3 for out parameter. Return value is available on //EchoResponse/EchoResult. Simple and effective.