Tuesday, March 11, 2008

In a previous post, I presented a PostSharp weaver that created a surrogate class for all your domain classes to help in serializing circular references (you know: Father.Children and Child.Father will cause WCF to go into a loop). The important enabler there was a List<object> that I held onto while (de)serializing. I was unhappy with the way I had solved that, so in this post, I'll just fix that.

Part of the problem was that the Server (dispatcher) has a correctly initialized OperationContext, where I could get to OperationContext.Current and do stuff. Extensions that were added in an earlier phase were no longer accessible though. A shame really.
Nicholas Allen was able to tell me how I could get a OperationContext going in the client. You can just create an OperationContext. I created a proxy class (by hand) that does this. People who love generated code are out of luck on this one, but I would recommend against using the generation tools of VS for WCF anyway.

My Proxyclass:

  0  public class PersonSvcClient : ClientBase<IPersonService>, IPersonService
  1 {
  2   public PersonSvcClient() : base ("PersonEndpoint")
  3   {
  4
  5   }
  6   #region IPersonService Members
  7
  8   public void SendPersonGraphToService(Person person)
  9   {
  10    using (new OperationContextScope(this.InnerChannel))
  11    {
  12     base.Channel.SendPersonGraphToService(person);
  13    }
  14   }
  15
  16   public Person GetPersonToClient()
  17   {
  18    using (new OperationContextScope(this.InnerChannel))
  19    {
  20     return base.Channel.GetPersonToClient();
  21    }
  22   }
  23
  24
  25   #endregion
  26 }

As you can see, I'm putting the actual calls inside a using block that just creates an operationcontextscope.

Now, if I were to subscribe to the OperationContext.Current.OperationCompleted, you would think that I had a great place to clean up. However, this event does not get thrown on the client (it works correctly on the server..). Weird.

However, now I have an OperationContext.Current in both client as server, so I can add an extension to it. Beware, I add this extension right in the surrogate. This way, it will stay around during the serialization process.

  0   public class MyContext : IExtension<OperationContext>
  1   {
  2    public static MyContext GetCurrentContext()
  3    {
  4     MyContext c = OperationContext.Current.Extensions.Find<MyContext>();
  5     if (c == null)
  6     {
  7      OperationContext.Current.Extensions.Add(c = new MyContext());
  8     }
  9
  10     return c;
  11    }
  12
  13    /// <summary>
  14    /// will keep our objects during serialization. Need to clear this before serialization (operation behavior)
  15    /// </summary>
  16    public List<object> serializationList = new List<object>();
  17
  18    /// <summary>
  19    /// will keep our objects during desrialization. Need to clear this before deserialization (operation behavior)
  20    /// </summary>
  21    /// <remarks>the key is the serialization ID that is transmitted by the </remarks>
  22    public Dictionary<int, object> deserializationList = new Dictionary<int, object>();
  23
  24    #region IExtension<OperationContext> Members
  25
  26    public void Attach(OperationContext owner)
  27    {
  28    }
  29
  30    public void Detach(OperationContext owner)
  31    {
  32    }
  33
  34    #endregion
  35   }

I've added a static GetCurrentContext method, that will add the context class if it does not exist, and return it.

Finally, now I can be sure that I have a safe place to store my lists, and it get's garbage collected properly.

Friday, October 15, 2010 8:56:00 AM (Romance Standard Time, UTC+01:00)
href="http://www.feetlockers.com/reebok-easytone-reebok-easytone-womens-shoes-c-25_28.html">Reebok Easytone Shoes</a> syndication. And then there are those who are having <a href="http://www.feetlockers.com/specials.html">Discount Reebok zigtech</a> trouble getting out of their own way.The folks who are not succeeding are the ones whose first question is “where do I find a good deal?” Early stage syndicators think they need to find a great deal, then raise capital, and they will be on their way toward success and profit. I usually counter that with some tough love and a reality check. Instead of looking for deals and Reebok shoes, a prudent <a href="http://www.feetlockers.com/reebok-easytone-reebok-zig-pulse-running-shoes-c-25_26.html">Reebok EasyTone</a> syndicator needs to put the horse in front of the deal, and start with the question of how to raise capital.
Friday, October 15, 2010 8:56:09 AM (Romance Standard Time, UTC+01:00)
back pain and lumbosacral joint.Moreover, the girls who wear high heels early will lead to <a href="http://www.zigtechshoesonsale.com/mbt-men-shoes-mbt-casual-shoes-c-8_9.html"><strong>Discount Mbt Shoes</strong></a> the developing pelvic tilt, which make the <a href="http://www.zigtechshoesonsale.com/mbt-men-shoes-mbt-sandals-shoes-c-8_11.html"><strong>Mbt shoes clearance</strong></a>, is demanding.However, they are not only for people on their feet but for anyone who wants to wear a pair of comfortable <a href="http://www.zigtechshoesonsale.com/mbt-women-shoes-mbt-sports-shoes-c-15_26.html"><strong>Mbt shoes outlet</strong></a> that takes the pain away from your body when you are standing and walking. That’s why you need to wear <a href="http://www.zigtechshoesonsale.com/mbt-men-shoes-mbt-casual-shoes-c-8_9.html"><strong>MBT Sandals Shoes</strong></a>.
Friday, October 15, 2010 12:27:21 PM (Romance Standard Time, UTC+01:00)
That is the type we have adorned with our attribute (your 'Person' Poco class, for instance). Then, I specify that I want 3 other aspects to work on this type!
Friday, October 22, 2010 9:48:36 AM (Romance Standard Time, UTC+01:00)
With the coming of Nike Air Max series,and the unique design and fashion style have made more and more young people love them. In Nike air max 2010,nike company had been released their newest product, it is called Nike Air Max 2009,which is also the latest nike air max 90 series,the shoes is made from a synthetic leather which using the latest technology to give a more smooth surface of the shoe. A non-pressurized forefoot and heel Air-Sole unit is integrated into the Cushlon midsole foam for a responsive ride.n our online stores,we provide Air Max 2009.
Friday, October 22, 2010 9:48:44 AM (Romance Standard Time, UTC+01:00)
<a href="http://www.shapeupsoutlet.com/"><strong>Shape Ups Shoes</strong></a> come in different colors and designs. They <a href="http://www.shapeupsoutlet.com/shape-ups-stability-c-8.html"><strong>Skechers Shape Ups</strong></a> the same midsole and outsole, so they should fit and feel the same. <a href="http://www.shapeupsoutlet.com/shapeups-sleek-fit-c-9.html"><strong>Skechers Shape up Shoes</strong></a> also come in extra wide widths in select styles for men and women.<a href="http://www.shapeupsoutlet.com/womens-shapeups-c-1.html"><strong>Skechers Shape Ups Shoes</strong></a> While You Walk
Tuesday, October 26, 2010 2:55:28 AM (Romance Standard Time, UTC+01:00)
href="http://www.feetlockers.com/reebok-easytone-c-25.html">Reebok ZigTech</a> tests the shoes on real runners who fill in a detailed questionnaire at the start, mid-way and end of 300-mile increments. They’re light, flexible and so comfortable. <a href="http://www.feetlockers.com/reebok-easytone-c-25.html">Reebok ZigTech shoes</a> footwear, training longer just got easier.<a href="http://www.feetlockers.com/reebok-easytone-reebok-easytone-womens-shoes-c-25_28.html">Reebok Easytone Shoes</a> has the top technology which uses shoes’ energy and transfers it horizontally. ZigTech helps to transfer weight through the whole range of motion by pushing the force of the strike through to the front of your foot. <a href="http://www.feetlockers.com/specials.html">Discount Reebok zigtech</a> footwear is designed to protect your feet and return energy to the athlete for a soft and springy ride. The foam is lightweight. Forefoot flex grooves for added <a href="http://www.feetlockers.com/reebok-easytone-reebok-zig-pulse-running-shoes-c-25_26.html">Reebok EasyTone</a> flexibility. This ultimately enables athletes to stay healthier during in this season.<br>
Tuesday, October 26, 2010 2:55:43 AM (Romance Standard Time, UTC+01:00)
href="http://www.zigtechshoesonsale.com/mbt-men-shoes-mbt-sandals-shoes-c-8_11.html"><strong>Cheap mbt shoes</strong></a> is not too high, if the heel is higher than 3.5 cm, it will increase the risk of lumbar lordosis and lumbosacral angle, which easily lead to fatigue and lower back pain and lumbosacral joint.Moreover, the girls who wear high heels early will lead to <a href="http://www.zigtechshoesonsale.com/mbt-men-shoes-mbt-casual-shoes-c-8_9.html"><strong>Discount Mbt Shoes</strong></a> the developing pelvic tilt, which make the <a href="http://www.zigtechshoesonsale.com/mbt-men-shoes-mbt-sandals-shoes-c-8_11.html"><strong>Mbt shoes clearance</strong></a>, is demanding.However, they are not only for people on their feet but for anyone who wants to wear a pair of comfortable <a href="http://www.zigtechshoesonsale.com/mbt-women-shoes-mbt-sports-shoes-c-15_26.html"><strong>Mbt shoes outlet</strong></a> that takes the pain away from your body when you are standing and walking. That’s why you need to wear <a href="http://www.zigtechshoesonsale.com/mbt-men-shoes-mbt-casual-shoes-c-8_9.html"><strong>MBT Sandals Shoes</strong></a>.
Monday, November 01, 2010 8:04:56 AM (Romance Standard Time, UTC+01:00)
I am happy to find this post very useful for me, as it contains lot of information. I always prefer to read the quality content and this thing I found in you post. Thanks for sharing
Thursday, November 04, 2010 4:39:17 AM (Romance Standard Time, UTC+01:00)
http://www.coachusabags.com/
http://www.asics-us.com/
http://www.ukuggus.com/
http://www.mbt-usa.com/
Sunday, November 07, 2010 4:05:04 AM (Romance Standard Time, UTC+01:00)
Quite lengthy but very informative article indeed. It gave me lot of insight.
Saturday, November 13, 2010 1:53:10 AM (Romance Standard Time, UTC+01:00)
It’s good to see you posting on this topic, I need to bookmark this web site. Keep up the good work.
Saturday, December 04, 2010 3:38:07 AM (Romance Standard Time, UTC+01:00)
<a href="http://www.fashioniphone.com/iphone-cases">iPhone covers</a>
<a href="http://www.fashioniphone.com/iphone-cases">iPhone plastic cases</a>
<a href="http://www.fashioniphone.com/iphone-cases">iphone skin</a>
<a href="http://www.fashioniphone.com/iphone-cases">iphone 3g skin</a>
<a href="http://www.fashioniphone.com/iphone-cases">iphone accessories cases</a>
Comments are closed.