Orcas: POX Service Support 

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.

Categories:  .NET 3.5 - WCF
Saturday, 10 March 2007 21:55:49 (Central Europe Standard Time, UTC+01:00)  #    Comments

 

Copyright © 2003-2024 , Matevž Gačnik
Recent Posts
RD / MVP
Feeds
RSS: Atom:
Archives
Categories
Blogroll
Legal

The opinions expressed herein are my own personal opinions and do not represent my company's view in any way.

My views often change.

This blog is just a collection of bytes.

Copyright © 2003-2024
Matevž Gačnik

Send mail to the author(s) E-mail