<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://msmvps.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Search results for 'app:weblogs' matching tag '.NET 3.5 Framework'</title><link>http://msmvps.com/search/SearchResults.aspx?q=app:weblogs&amp;tag=.NET+3.5+Framework&amp;orTags=0&amp;o=DateDescending</link><description>Search results for 'app:weblogs' matching tag '.NET 3.5 Framework'</description><dc:language>en-US</dc:language><generator>CommunityServer 2008.5 SP2 (Build: 40407.4157)</generator><item><title>WF Persistence - Where [DataContract] != [Serializable]</title><link>http://msmvps.com/blogs/williamryan/archive/2008/11/01/wf-persistence-where-datacontract-serializable.aspx</link><pubDate>Sat, 01 Nov 2008 05:00:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1652742</guid><dc:creator>William</dc:creator><description>&lt;p&gt;Let&amp;#39;s say you were using Workflow Foundation (WF) and Windows Communication Foundation (WCF). Assume you wanted to use WF&amp;#39;s Persistence mechanism (which requires types to be &lt;a href="http://msdn.microsoft.com/en-us/library/system.serializableattribute(VS.71).aspx"&gt;Serializable&lt;/a&gt;). And assume that all the objects you were using in the workflow were decorated with the &lt;a href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractattribute.aspx"&gt;[DataContract]&lt;/a&gt; attribute.&amp;nbsp; Would you expect any problems related to Serialization?&amp;nbsp; &lt;em&gt;(I can but to the chase really quickly here if you don&amp;#39;t want my belabored background information and explanation. If you&amp;#39;re creating a type to use w/ Workflow Foundation that will be saved via the Workflow Foundation Persistence Service which makes use of the &lt;a href="http://msdn.microsoft.com/en-us/library/system.workflow.runtime.hosting.sqlworkflowpersistenceservice.aspx"&gt;SqlWorkflowPersistenceService&lt;/a&gt; class, marking the class as a &lt;a href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractattribute.aspx"&gt;[DataContract]&lt;/a&gt; alone will not work for WF&amp;#39;s persistence mechanism. It does make the class &lt;a href="http://msdn.microsoft.com/en-us/library/system.serializableattribute(VS.71).aspx"&gt;serializable&lt;/a&gt; in a literal sense and will suffice [provided you meet the other requirements of a &lt;a href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractattribute.aspx"&gt;[DataContract]&lt;/a&gt;  for WCF&amp;#39;s serialization needs, but it is insufficient for WF (see the References section at the end of this post for more details on WF Serialization) - so make sure you use the &lt;a href="http://msdn.microsoft.com/en-us/library/system.serializableattribute(VS.71).aspx"&gt;Serializable&lt;/a&gt; attribute on any type that&amp;#39;ll be consumed by the Persistence Service).&lt;/em&gt;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;MSDN describes the &lt;/strong&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractattribute.aspx"&gt;&lt;strong&gt;DataContract class&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt; the following way:&lt;/strong&gt;&lt;/p&gt; &lt;blockquote&gt; &lt;p align="left"&gt;&lt;em&gt; Specifies that the type defines or implements a data contract and is serializable by a serializer, such as&amp;nbsp;&amp;nbsp; the &lt;/em&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractserializer.aspx"&gt;&lt;em&gt;DataContractSerializer&lt;/em&gt;&lt;/a&gt;&lt;em&gt;. To make their type &lt;a href="http://msdn.microsoft.com/en-us/library/system.serializableattribute(VS.71).aspx"&gt;serializable&lt;/a&gt;, type authors must define a data contract for their type.&lt;/em&gt; &lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;If you spend a lot of time in WCF, you&amp;#39;d likely assume that b/c types decorated with the &lt;a href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractattribute.aspx"&gt;DataContract&lt;/a&gt; attribute would satisfy any requirement for the type to be &lt;a href="http://msdn.microsoft.com/en-us/library/system.serializableattribute(VS.71).aspx"&gt;Serializable&lt;/a&gt;.&amp;nbsp; But you&amp;#39;d likely be wrong. Yes, a type that is a &lt;a href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractattribute.aspx"&gt;[DataContract]&lt;/a&gt;&amp;nbsp; is serializable in the literal sense, but it&amp;#39;s serialized by the &lt;a href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractserializer.aspx"&gt;DataContractSerializer&lt;/a&gt; (see the &lt;em&gt;References&lt;/em&gt; section at the end of this post for more details on WF Serialization) &lt;p&gt;So why is this an issue and what do you do about it?&amp;nbsp; Often, non-trivial workflows span an amount of time that exceeds any given user&amp;#39;s session.&amp;nbsp; In fact, it&amp;#39;s not uncommon for a non-trivial workflow to span as much as 30 days.&amp;nbsp; Using a simple example, let&amp;#39;s say that you are writing a Workflow to manage new employees.&amp;nbsp; Further assume that there are several document requirements and that any deficiencies would result in severe penalties or liability risks.&amp;nbsp; Just to make it clear, assume that each of the following must be procured before a new employee can start working.&amp;nbsp; Further, assume that b/c of fees associated with each, if any previous one fails, that the whole process terminates (if someone&amp;#39;s reference checks don&amp;#39;t pass, there&amp;#39;s no need to spend the money for a full background investigation as you know you&amp;#39;re not going to hire them). [Also, this isn&amp;#39;t a post on workplace hiring guidelines and is solely used for illustration - no need to point out why &amp;#39;its bad business to drug test or whatever else]. &lt;ol&gt; &lt;li&gt;Employment Application&lt;/li&gt; &lt;li&gt;Proof of Citizenship or ability to work in the U.S.&lt;/li&gt; &lt;li&gt;State withholding form&lt;/li&gt; &lt;li&gt;Federal withholding form&lt;/li&gt; &lt;li&gt;Reference check&lt;/li&gt; &lt;li&gt;License check&lt;/li&gt; &lt;li&gt;Completed Drug Screen&lt;/li&gt; &lt;li&gt;Full Background check&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;Implementation policies will vary from company to company but assume that all of these tasks wouldn&amp;#39;t be completed within the user session that first created the entity. If you couldn&amp;#39;t persist the workflow somehow and come back to it later, it would be of very little use.&amp;nbsp;&amp;nbsp; Workflow foundation provides an out-of-the-box solution named not surprisingly -&amp;nbsp; &lt;a href="http://msdn.microsoft.com/en-us/library/ms735722(VS.85).aspx"&gt;Windows Workflow Persistence Service&lt;/a&gt; to help with long running workflows&lt;/p&gt; &lt;p&gt;Since Workflow Foundation is still in its infancy in terms of user adoption, many shops don&amp;#39;t have well established design rules in place specifically for Workflow items.&amp;nbsp; This can have some profound (although easily addressed in most cases) effects on Workflow development. It&amp;#39;s common for a workflow to start out small in terms of steps and happen relatively quickly.&amp;nbsp; When this is the case, there&amp;#39;s little need for a persistence mechanism for the workflow.&amp;nbsp; But as people get comfortable with WF and are willing to try more involved solutions, steps get added that often increase the time span the workflow could run to a point that&amp;#39;s longer than the user session.&amp;nbsp; For people new to WF, adding that first activity that&amp;#39;ll possibly span a large amount of time is the first time they actually think seriously about the persistence service. And that&amp;#39;s the point at which they often go back and try to retrofit things.&amp;nbsp; In many cases, the number of &amp;quot;things&amp;quot; will be fairly substantial so it&amp;#39;s quite easy to overlook something.&amp;nbsp; Once you implement the persistence service, you&amp;#39;ll typically go through the testing phase and make sure everything persist and can be retrieved correctly.&amp;nbsp; And this is the time serialization problems with show themselves - often in a manner that&amp;#39;s hard to isolate b/c the number of items involved.&amp;nbsp; &lt;/p&gt; &lt;p&gt; In some cases, if there&amp;#39;s a serialization problem, a fault will result.&amp;nbsp; &lt;a href="http://odetocode.com/Blogs/scott/archive/2007/01/24/9943.aspx"&gt;Unhandled faults&lt;/a&gt; in WF cause behavior that deviates from what you&amp;#39;d typically expect. So depending on your logging and tracing, you may or may not find the issue quickly. in many cases, you&amp;#39;ll find the fault is related to serialization and you&amp;#39;ll address it on the specific type, then go back and try to find every other type and make it &lt;a href="http://msdn.microsoft.com/en-us/library/system.serializableattribute(VS.71).aspx"&gt;serializable&lt;/a&gt; as well.&amp;nbsp; This is likely to be overkill though - b/c you&amp;#39;re likely to have some types that aren&amp;#39;t involved in anything that&amp;#39;s persisted and consequently don&amp;#39;t require persistence.&amp;nbsp; So you try to only make the items that will be persisted &lt;a href="http://msdn.microsoft.com/en-us/library/system.serializableattribute(VS.71).aspx"&gt;serializable&lt;/a&gt;. Until you get to the point where you&amp;#39;re addressing everything in the planning and design stages, you&amp;#39;re likely to run into situations like this and the only way out typically involves a lot of trial-and-error.&amp;nbsp; That&amp;#39;s why this post is relevant. If you go back and define each type that will be persisted as a &lt;a href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractattribute.aspx"&gt;[DataContract]&lt;/a&gt; , it&amp;#39;ll take you some time to do, may necessitate you adding new references to some projects and ultimately, after all that&amp;#39;s done, won&amp;#39;t fix the problem. The following type may work all day long when just dealing with WCF&amp;#39;s serialization requirements...&lt;/p&gt; &lt;p&gt;namespace Ger911.HCStandard.Core.Shared&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; [DataContract]&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public class MatrixItem&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [DataMember]&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public String EntityName { get; set; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [DataMember]&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public String ContactName { get; set; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [DataMember]&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public Int32 BedCount { get; set; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [DataMember]&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public String HospitalStatus { get; set; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [DataMember]&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public DateTime ModifiedDateTime { get; set; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;} &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;But unless you modify it like this, you&amp;#39;ll be in for some unpleasant surprises in WF:&lt;/p&gt; &lt;p&gt;namespace Ger911.HCStandard.Core.Shared&lt;br /&gt;{&lt;/p&gt; &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; [Serializable]&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; [DataContract]&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public class MatrixItem&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [DataMember]&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public String EntityName { get; set; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [DataMember]&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public String ContactName { get; set; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [DataMember]&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public Int32 BedCount { get; set; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [DataMember]&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public String HospitalStatus { get; set; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [DataMember]&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public DateTime ModifiedDateTime { get; set; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;}&lt;/p&gt; &lt;p&gt;References:&lt;/p&gt; &lt;p&gt;Using &lt;a href="http://www.red-gate.com/products/reflector/"&gt;Red Gate&amp;#39;s Reflector&lt;/a&gt;, here&amp;#39;s what you&amp;#39;ll see under the hood of the &lt;a href="http://msdn.microsoft.com/en-us/library/system.workflow.runtime.hosting.workflowpersistenceservice.aspx"&gt;WorkflowPesistenceService&lt;/a&gt; class&amp;#39;s &lt;a href="http://msdn.microsoft.com/en-us/library/system.workflow.runtime.hosting.workflowpersistenceservice.restorefromdefaultserializedform.aspx"&gt;RestoreFromDefaultSerializedForm&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/system.workflow.runtime.hosting.workflowpersistenceservice.getdefaultserializedform.aspx"&gt;GetDefaultSerializedForm&lt;/a&gt;.&amp;nbsp; For further insight into this, use &lt;a href="http://www.red-gate.com/products/reflector/"&gt;Reflector&lt;/a&gt; and examine the &lt;a href="http://msdn.microsoft.com/en-us/library/system.workflow.runtime.hosting.sqlworkflowpersistenceservice.aspx"&gt;SqlWorkflowPersistenceService&lt;/a&gt;:&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;font size="3"&gt;&lt;strong&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.workflow.runtime.hosting.workflowpersistenceservice.restorefromdefaultserializedform.aspx"&gt;RestoreFromDefaultSerializedForm&lt;/a&gt;&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt; &lt;p&gt;protected static Activity RestoreFromDefaultSerializedForm(byte[] activityBytes, Activity outerActivity)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Activity activity;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DateTime now = DateTime.Now;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MemoryStream stream = new MemoryStream(activityBytes);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; stream.Position = 0L;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; using (GZipStream stream2 = new GZipStream(stream, CompressionMode.Decompress, true))&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; activity = Activity.Load(stream2, outerActivity);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TimeSpan span = (TimeSpan)(DateTime.Now - now);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0, &amp;quot;Deserialized a {0} to length {1}. Took {2}.&amp;quot;,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; new object[] { activity, stream.Length, span }); return activity;&lt;br /&gt; } &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;&lt;font size="3"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.workflow.runtime.hosting.workflowpersistenceservice.getdefaultserializedform.aspx"&gt;GetDefaultSerializedForm&lt;/a&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;protected static byte[] GetDefaultSerializedForm(Activity activity)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DateTime now = DateTime.Now;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; using (MemoryStream stream = new MemoryStream(0x2800))&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; stream.Position = 0L;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; activity.Save(stream);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; using (MemoryStream stream2 = new MemoryStream((int)stream.Length))&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; using (GZipStream stream3 = new GZipStream(stream2, CompressionMode.Compress, true))&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; stream3.Write(stream.GetBuffer(), 0, (int)stream.Length);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ActivityExecutionContextInfo info = (ActivityExecutionContextInfo)activity.GetValue(Activity.ActivityExecutionContextInfoProperty);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TimeSpan span = (TimeSpan)(DateTime.Now - now);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0, &amp;quot;Serialized a {0} with id {1} to length {2}. Took {3}.&amp;quot;, new object[] { info, info.ContextGuid, stream2.Length, span });&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; byte[] array = stream2.GetBuffer();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Array.Resize&amp;lt;byte&amp;gt;(ref array, Convert.ToInt32(stream2.Length));&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return array;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;} &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractserializer.aspx"&gt;&lt;font size="3"&gt;&lt;strong&gt;DataContractSerializer&lt;/strong&gt;&lt;/font&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;public sealed class DataContractSerializer : XmlObjectSerializer&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Fields&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; private IDataContractSurrogate dataContractSurrogate;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; private bool ignoreExtensionDataObject;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; internal Dictionary&amp;lt;XmlQualifiedName, DataContract&amp;gt; knownDataContracts;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; private ReadOnlyCollection&amp;lt;Type&amp;gt; knownTypeCollection;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; internal IList&amp;lt;Type&amp;gt; knownTypeList;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; private int maxItemsInObjectGraph;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; private bool needsContractNsAtRoot;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; private bool preserveObjectReferences;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; private DataContract rootContract;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; private XmlDictionaryString rootName;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; private XmlDictionaryString rootNamespace;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; private Type rootType;  &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Methods&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public DataContractSerializer(Type type);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public DataContractSerializer(Type type, IEnumerable&amp;lt;Type&amp;gt; knownTypes);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public DataContractSerializer(Type type, string rootName, string rootNamespace);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public DataContractSerializer(Type type, XmlDictionaryString rootName, XmlDictionaryString rootNamespace);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public DataContractSerializer(Type type, string rootName, string rootNamespace, IEnumerable&amp;lt;Type&amp;gt; knownTypes);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public DataContractSerializer(Type type, XmlDictionaryString rootName, XmlDictionaryString rootNamespace, IEnumerable&amp;lt;Type&amp;gt; knownTypes);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public DataContractSerializer(Type type, IEnumerable&amp;lt;Type&amp;gt; knownTypes, int maxItemsInObjectGraph, bool ignoreExtensionDataObject, bool preserveObjectReferences, IDataContractSurrogate dataContractSurrogate);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public DataContractSerializer(Type type, string rootName, string rootNamespace, IEnumerable&amp;lt;Type&amp;gt; knownTypes, int maxItemsInObjectGraph, bool ignoreExtensionDataObject, bool preserveObjectReferences, IDataContractSurrogate dataContractSurrogate);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public DataContractSerializer(Type type, XmlDictionaryString rootName, XmlDictionaryString rootNamespace, IEnumerable&amp;lt;Type&amp;gt; knownTypes, int maxItemsInObjectGraph, bool ignoreExtensionDataObject, bool preserveObjectReferences, IDataContractSurrogate dataContractSurrogate);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; internal static DataContract GetDataContract(DataContract declaredTypeContract, Type declaredType, Type objectType);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; internal override Type GetDeserializeType();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; internal override Type GetSerializeType(object graph);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; internal static Type GetSurrogatedType(IDataContractSurrogate dataContractSurrogate, Type type);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; private void Initialize(Type type, IEnumerable&amp;lt;Type&amp;gt; knownTypes, int maxItemsInObjectGraph, bool ignoreExtensionDataObject, bool preserveObjectReferences, IDataContractSurrogate dataContractSurrogate);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; private void Initialize(Type type, XmlDictionaryString rootName, XmlDictionaryString rootNamespace, IEnumerable&amp;lt;Type&amp;gt; knownTypes, int maxItemsInObjectGraph, bool ignoreExtensionDataObject, bool preserveObjectReferences, IDataContractSurrogate dataContractSurrogate);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; internal override bool InternalIsStartObject(XmlReaderDelegator reader);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; internal override object InternalReadObject(XmlReaderDelegator xmlReader, bool verifyObjectName);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; internal override void InternalWriteEndObject(XmlWriterDelegator writer);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; internal override void InternalWriteObject(XmlWriterDelegator writer, object graph);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; internal override void InternalWriteObjectContent(XmlWriterDelegator writer, object graph);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; internal override void InternalWriteStartObject(XmlWriterDelegator writer, object graph);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public override bool IsStartObject(XmlDictionaryReader reader);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public override bool IsStartObject(XmlReader reader);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public override object ReadObject(XmlReader reader);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public override object ReadObject(XmlDictionaryReader reader, bool verifyObjectName);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public override object ReadObject(XmlReader reader, bool verifyObjectName);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; internal static object SurrogateToDataContractType(IDataContractSurrogate dataContractSurrogate, object oldObj, Type surrogatedDeclaredType, ref Type objType);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public override void WriteEndObject(XmlDictionaryWriter writer);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public override void WriteEndObject(XmlWriter writer);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public override void WriteObject(XmlWriter writer, object graph);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public override void WriteObjectContent(XmlDictionaryWriter writer, object graph);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public override void WriteObjectContent(XmlWriter writer, object graph);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public override void WriteStartObject(XmlDictionaryWriter writer, object graph);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public override void WriteStartObject(XmlWriter writer, object graph);  &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Properties&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public IDataContractSurrogate DataContractSurrogate { get; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public bool IgnoreExtensionDataObject { get; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; internal Dictionary&amp;lt;XmlQualifiedName, DataContract&amp;gt; KnownDataContracts { get; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public ReadOnlyCollection&amp;lt;Type&amp;gt; KnownTypes { get; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public int MaxItemsInObjectGraph { get; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public bool PreserveObjectReferences { get; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; private DataContract RootContract { get; }&lt;br /&gt;}&lt;/p&gt;</description></item><item><title>WCF to the rescue</title><link>http://msmvps.com/blogs/williamryan/archive/2008/07/07/wcf-to-the-rescue.aspx</link><pubDate>Mon, 07 Jul 2008 05:00:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1639700</guid><dc:creator>William</dc:creator><description>&lt;p&gt;Although part of the idea below was mine, James Ashley was crucial to helping me figure this out.&lt;/p&gt; &lt;p&gt;Problem:&lt;/p&gt; &lt;p&gt;Without getting into the ghoury details, we have an application that allows users to send messages to large groups of people.&amp;nbsp; Anyone using a client application that is logged on will get a special notification which they can respond to once a message is sent. So far, Polling has been the bane of our existence.&amp;nbsp; We&amp;#39;re trying to fancy up the UI and Telerik&amp;#39;s Winforms controls have helped out a lot, but there&amp;#39;s simply no way I&amp;#39;ve been able to find to have a snappy UI with a lot of really cool looking effects - all the while polling every few seconds.&amp;nbsp; Until now, I just bit down, and took a walk through multi-threadedville.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;I wanted to remove the polling.&amp;nbsp; We had experimented with a few different architectures, but all had the same problem, polling.&amp;nbsp; So let&amp;#39;s say you had 200 users logged on.&amp;nbsp; In the User&amp;#39;s bar, we wanted to show each user and their picture - much the same way IM does.&amp;nbsp; This app had to work across network boundaries and you couldn&amp;#39;t count on being able to use TCP so we had to at least make it work with http.&amp;nbsp; If you poll every three seconds, to get the latest info on who&amp;#39;s logged on and off, rebuilding the list of user&amp;#39;s was painful. We resorted to several tricks to determine if a user was already in the list, but all of it was putting lipstick on a pig.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Solution:&lt;/p&gt; &lt;p&gt;One of the big things you often hear about with WCF is self-hosting.&amp;nbsp; I had ignored it for the most part.&amp;nbsp; But today, I wanted to basically have a Winforms app host one service, and a Windows Service host the other part of the service, having the services talk to each other. The client winforms app would simply talk to the client service, it would never hit the Windows Service directly.&lt;/p&gt; &lt;p&gt;So we built a client service and server service, with a client winforms app hosting the client service and a mock Windows Service (which was simply another winforms app) that hosted the service.&lt;/p&gt; &lt;p&gt;The problem we kept running into is as each client signed on to the system, how could we tell the server svc that they were online?&amp;nbsp; Dynamically adding endpoints is child&amp;#39;s play, but with each winforms app, you could only interact with the ServiceHost - not the service.&lt;/p&gt; &lt;p&gt;We tried using traditional events to no avail - that wasn&amp;#39;t a surprise but we figured it&amp;#39;s worth a try.&amp;nbsp; Then James recommended a static event. I was completely skeptical, but alas it worked.&amp;nbsp; &lt;/p&gt; &lt;p&gt;After looking at Juval&amp;#39;s framework though, it became really clear. If we want the services to be able to interact with the hosts, then simply self-host the things.&lt;/p&gt; &lt;p&gt;So we had a method called ReceiveMessage which was called from the service (via a client proxy for the client service).&amp;nbsp; Here&amp;#39;s basically what the client looked like:&lt;/p&gt; &lt;p&gt;public partial class Form1 : Form, IClientService&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public Form1()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; InitializeComponent();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }  &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ServiceHost currentHost = null;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; private void btnStartService_Click(object sender, EventArgs e)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; currentHost = new ServiceHost(typeof(Form1));&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; try&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; currentHost.Open();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lblServiceStatus.Text = &amp;quot;Started&amp;quot;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; catch (Exception ex)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lblServiceStatus.Text = ex.Message;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }  &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public string ReceiveMessage(string msg)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; String myMessage = msg;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MessageBox.Show(myMessage);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return msg;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;p&gt;.... &lt;p&gt;&amp;nbsp; &lt;p&gt;Now, from the Administrative application (which interacted with the service, you could Send a message by doing the following:) &lt;p&gt;private void btnSend_Click(object sender, EventArgs e)&lt;br /&gt;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; proxy = new ClientServiceClient(new NetNamedPipeBinding(), endpoint );&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; try&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; proxy.ReceiveMessage(rtbMessageText.Text);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; catch (FaultException ex)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lblServiceStatus.Text = ex.Message;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp; } &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;ClientServiceClient is a stupid name for a client proxy class, but we were just experimenting - the main thing to note is that it&amp;#39;s simply a proxy class for the client service, the same service that&amp;#39;s effectively being hosted by the Winforms client.&amp;nbsp; There&amp;#39;s a server method called SendMessage(String msg) which you&amp;#39;d call on the service, which in turn would dynamically add endpoints for each active client , and then send the messages to them.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;You can easily store all the information for clients you want to send messages to in a List&amp;lt;&amp;gt; or similar structure - or if you need stronger persistence or have different needs, then you can use a database.&amp;nbsp; Either way the end result is the same - loop through all the clients, add an endpoint for each one, loop through each and call the method you want.&lt;/p&gt; &lt;p&gt;I&amp;#39;m having trouble getting to my ftp server from where i&amp;#39;m at, but I&amp;#39;ll post the code when I can. In the meantime, if you&amp;#39;re interested, just drop me a line.&lt;/p&gt;</description></item><item><title>Looking for some .NET Developers</title><link>http://msmvps.com/blogs/williamryan/archive/2008/06/06/looking-for-some-net-developers.aspx</link><pubDate>Fri, 06 Jun 2008 05:00:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1632527</guid><dc:creator>William</dc:creator><description>&lt;p&gt;A client of mine located in the Aiken/Columbia South Carolina Area has asked me if I had any friends who are .NET Developers and looking for a job. They are looking for at least one Junior Developer, on Mid-Level Developer and several Senior developers.&amp;nbsp; I know these folks quite well and I can vouch for the following:&amp;nbsp; &lt;/p&gt; &lt;ul&gt; &lt;li&gt;They pay extremely well&lt;/li&gt; &lt;li&gt;Generous benefits package&lt;/li&gt; &lt;li&gt;There&amp;#39;s plenty of cool people on their staff&lt;/li&gt; &lt;li&gt;They are growing at an explosive rate so there&amp;#39;s plenty of room for upward mobility. There&amp;#39;s also a very strong focus on learning/teaching and career development.&lt;/li&gt; &lt;li&gt;They are an Agile/SCRUM shop&lt;/li&gt; &lt;li&gt;Currently developing with the following technologies:&lt;/li&gt; &lt;ul&gt; &lt;li&gt; Visual Studio Team System 2008 / .NET 3.5 Framework&lt;/li&gt; &lt;li&gt;Windows Communication Foundation&lt;/li&gt; &lt;li&gt;Windows Presentation Foundation&lt;/li&gt; &lt;li&gt;ASP.NET&lt;/li&gt; &lt;li&gt;LINQ&lt;/li&gt; &lt;li&gt;Silverlight&lt;/li&gt; &lt;li&gt;Windows Mobile 5/ Windows Mobile 6/ .NET Compact Framework&lt;/li&gt; &lt;li&gt;Sql Server 2005 / Sql Server 2008&lt;/li&gt; &lt;li&gt;Windows Installer for XML&lt;/li&gt; &lt;li&gt;Sandcastle&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt; &lt;p&gt;If you&amp;#39;re in the area and looking for a job... if you know someone who looking for a job.... or if you&amp;#39;re willing to move, please drop me a line using the Contact option on&amp;nbsp; my blog or emailing me directly at &lt;a href="mailto://WilliamRyan@gmail.com"&gt;WilliamRyan@gmail.com&lt;/a&gt; and I&amp;#39;ll put you in contact with them.&amp;nbsp; They are looking to hire folks immediately so I can probably get you an interview within a few days.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Junior Developer:&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;Ideal candidate will be a recent college graduate with a Computer Science of MIS degree.&amp;nbsp; No experience is necessary for this position. The main soft-skill qualifications for this position are:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;A true love for development&lt;/li&gt; &lt;li&gt;Strong desire to learn&lt;/li&gt; &lt;li&gt;A desire to stand out among one&amp;#39;s peers&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt; The hard-skill qualifications include a good theoretical understanding of at least two of the following:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Object Oriented Design and Analysis&lt;/li&gt; &lt;li&gt;Relational Database theory&lt;/li&gt; &lt;li&gt;Design Patterns&lt;/li&gt; &lt;li&gt;Familiarity with at least two of the following:&amp;nbsp; C, C++, Java, C#, VB.NET&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;This is essentially a dream job for recent college grads b/c the job is being offered &amp;quot;no experience required&amp;quot;.&amp;nbsp; Since they are a SCRUM/Agile shop, you&amp;#39;ll get to work extensively with their Senior and Mid level devs via Pair Programming.&amp;nbsp;&amp;nbsp; You&amp;#39;ll be able to pick&amp;nbsp; an area to specialize in which you will decide on for yourself. Additionally, you&amp;#39;ll be using some of the most sought after Microsoft technologies available.&amp;nbsp; Go to Monster.com or Dice.com and see for yourself how much demand there is for the above technologies and how much those jobs pay.&amp;nbsp; You&amp;#39;ll get to work with these on day 1 and essentially carve out a path for yourself using whichever technologies you like the best.&amp;nbsp; If you want to be a &amp;quot;UI&amp;quot; expert, that&amp;#39;s where you&amp;#39;ll be put. If you want to be a Web Services dev, again, that&amp;#39;s what you can focus on.&amp;nbsp; If you want to be an expert buildmaster who specializes in installers, that&amp;#39;s what you&amp;#39;ll get to do.&amp;nbsp; The company is looking for some excellent candidates and willing to offer a really fun and great paying job with plenty of training and career development available.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Mid-Level Developer:&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;The ideal candidate will have a computer science or MIS degree and 1-3 years of development experience.&amp;nbsp; The ideal candidate will have two or more the following abilities:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Solid command of OOP/OOD using C++, C#, Java or VB.NET&lt;/li&gt; &lt;li&gt;Test Driven Design&lt;/li&gt; &lt;li&gt;Service Oriented Architecture&lt;/li&gt; &lt;li&gt;Familiarity with MySql, Sql Server (T-SQL), Oracle (PL/SQL)&lt;/li&gt; &lt;li&gt;Basic understanding of both Winforms and ASP.NET&lt;/li&gt; &lt;li&gt;Basic familiarity with Web Services, MSMQ, Enterprise Services/COM+, .NET Remoting, DCOM, J2EE, Java Beans&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;Just like the Junior development positions, these ones will provide a great deal of flexibility to learn and specialize the area of your choice.&amp;nbsp; These are considered &amp;#39;fast track&amp;#39; positions to move into the Senior Developer or Architect roles&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Senior Developer:&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;The ideal candidate will be someone with at least 4 years experience.&amp;nbsp; This person will love challenges and love coming up with solutions to problems that other people run from.&amp;nbsp; They will be people that love figuring out how to do things that everyone else said can&amp;#39;t be done.&amp;nbsp; They will be the stereotypical Alpha-Geek, Someone that spends their spare time &lt;a href="http://newtechusa.com/csharp-dotnet-quiz.asp"&gt;answering quiz questions like these&lt;/a&gt;:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;All of the requirements for the Mid-Level Developer as well as several of the following skills:&lt;/li&gt; &lt;ul&gt; &lt;li&gt;Proficiency with T-Sql or PL/SQL.&amp;nbsp; You should be able to write a 5 table join on your own. You should have written several stored procedures that were &amp;gt; 100 lines long.&lt;/li&gt; &lt;li&gt;Strong command of query tuning and ability to easily spot design flaws&lt;/li&gt; &lt;li&gt;Ability to design &amp;#39;real&amp;#39; objects.&amp;nbsp; &lt;/li&gt; &lt;ul&gt; &lt;li&gt;Someone who pays meticulous attention to the scope modifiers of their classes/functions/properties&lt;/li&gt; &lt;li&gt;Someone who understands the problems associated with coupling and strives to avoid it.&lt;/li&gt; &lt;li&gt;Someone who can write and use events in their classes without thinking twice about it.&lt;/li&gt; &lt;li&gt;Someone with a solid understanding of thread safety and thread synchronization&lt;/li&gt; &lt;li&gt;Someone who is comfortable using several different design patterns&lt;/li&gt; &lt;li&gt;Someone who is comfortable implementing several different interfaces in one object, using combinations of interface implementation and inheritance and someone who can use inheritance responsibly&lt;/li&gt;&lt;/ul&gt; &lt;li&gt;Keeps up with technology, reads computer books regularly, has favorite blogs in multiple disciplines and/or blogs themselves, attends or speaks at user&amp;#39;s groups, is active in one or more online forum or newsgroup&lt;/li&gt; &lt;li&gt;Someone who answers &amp;quot;Which is better, C# or VB.NET?&amp;quot; with &amp;quot;Either can be better depending on the circumstances but I&amp;#39;m comfortable writing in either of them&amp;quot; and then &amp;quot;But I&amp;#39;ve been learning F# lately and it&amp;#39;s really been growing on me&amp;quot;&lt;/li&gt; &lt;li&gt;Experience with .NET Remoting, Web Services &amp;amp; Web Services Enhancements, MSMQ, Enterprise Services and/or WCF&lt;/li&gt; &lt;li&gt;Ability to create syntactically correct UML diagrams (meaning they can do more than write the letters &amp;quot;UML&amp;quot; on their resume) and if not, they are willing to learn to do this.&lt;/li&gt; &lt;li&gt;Understands data structures solidly and could easily implement their own HashTable or LinkedList &lt;/li&gt; &lt;li&gt;Someone who&amp;#39;s always looking to come up with a newer, cooler, faster, and more secure way to do implement something&lt;/li&gt; &lt;li&gt;Experienced with either Biztalk server or Sharepoint&lt;/li&gt; &lt;li&gt;Takes pride in their code without falling in love with it or getting all defensive about it.&amp;nbsp; Ability to acknowledge the fact that everyone makes mistakes and can talk about their mistakes/bugs without getting defensive.&lt;/li&gt; &lt;li&gt;Someone who is the first to raise their hand whenever the boss says &amp;quot;I need someone to learn ____________, do I have any volunteers&amp;quot;&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt; &lt;p&gt;Basically, if you love development, love creating new cutting edge solutions all the while making a lot of money and having a lot of fun you definitely should talk to these folks.&amp;nbsp; If you&amp;#39;re interested...... Please drop me a line using the Contact option on&amp;nbsp; my blog or emailing me directly at &lt;a href="mailto://WilliamRyan@gmail.com"&gt;WilliamRyan@gmail.com&lt;/a&gt; and I&amp;#39;ll put you in contact with them.&lt;/p&gt;</description></item><item><title>Cool Powershell script</title><link>http://msmvps.com/blogs/williamryan/archive/2008/05/20/cool-powershell-script.aspx</link><pubDate>Tue, 20 May 2008 05:00:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1625389</guid><dc:creator>William</dc:creator><description>&lt;p&gt;I can&amp;#39;t take credit for this, I came across it in &lt;a href="http://www.amazon.com/Windows-Communication-Foundation-Unleashed-WCF/dp/0672329484"&gt;Windows Communication Foundation Unleashe&lt;/a&gt;d - but it&amp;#39;s very helpful for administering &lt;a href="http://msdn.microsoft.com/en-us/netframework/aa663324.aspx"&gt;Windows Communication Foundation&lt;/a&gt;...&lt;/p&gt; &lt;p&gt;In the &amp;lt;diagnostics&amp;gt; tag of your service&amp;#39;s configuration, two available options are &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.configuration.diagnosticsection.wmiproviderenabled.aspx"&gt;wmiProviderEnabled&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.configuration.diagnosticsection.performancecounters.aspx"&gt;performanceCounters&lt;/a&gt;.&amp;nbsp; So ideally you&amp;#39;ll want to set both, but if you just need to identify the endpoint then only the first one is necessary:&lt;/p&gt; &lt;p&gt;&lt;font size="1" face="Courier New"&gt;&amp;lt;system.serviceModel&amp;gt;&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="1" face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;diagnostics &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="1" face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; wmiProviderEnabled=&amp;quot;true&amp;quot;&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="1" face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; performanceCounters=&amp;quot;ServiceOnly&amp;quot;/&amp;gt;&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="1" face="Courier New"&gt;&amp;lt;/system.ServiceModel&amp;gt;&lt;/font&gt;&lt;/p&gt; &lt;p&gt;After you have that in place for your service(s), you can use the following Powershell script&lt;/p&gt; &lt;p&gt;&lt;font size="1" face="Courier New"&gt;PS C:\Windows\System32&amp;gt; get-wmiobject endpoint -n root\ServiceModel | ft name&lt;/font&gt;&lt;/p&gt; &lt;p&gt;I don&amp;#39;t know if I love Powershell more than Windows Communication Foundation or WCF more than Powershell, but few things are cooler than using them together and this is one script you&amp;#39;ll undoubtedly find helpful.&lt;/p&gt;</description></item><item><title>ChannelFactory.CreateChannel goes to the Gentlemen's Club</title><link>http://msmvps.com/blogs/williamryan/archive/2008/05/12/channelfactory-createchannel-goes-to-the-gentlemen-s-club.aspx</link><pubDate>Mon, 12 May 2008 05:00:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1621334</guid><dc:creator>William</dc:creator><description>&lt;p&gt;Currently, I&amp;#39;m tasked with getting some people up to speed on .NET 3.5 as well as WCF.&amp;nbsp; WCF is really cool and it&amp;#39;s easy to fall in love with, but it&amp;#39;s also easy to cause you to sleep when you&amp;#39;re first learning it. So instead of walking through Hello World, I changed course.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;Basically, we&amp;#39;re using an architecture where the Business Layer and Data Layer are services. In most cases, we&amp;#39;d run them on the same machine, in Proc. In other cases, when scalability is more of an issue, we&amp;#39;d need to separate them out.&lt;/p&gt;
&lt;p&gt;Creating Services is nothing special and other than a few attributes (ServiceContract, OperationContract, often DataContract and/or DataMember or EnumMember) and an interface, there&amp;#39;s no real way to tell a wcf service from any other class (and since most of those attributes should&amp;nbsp;go on the interface, the class itself shows no sign of being a service other than the interface implementation).&amp;nbsp; One thing though, when you add a WCF service to an application through VS, it will stick the service class and the corresponding interface into the same project.&amp;nbsp; I typically move my interfaces out of the project and into a library so that I can share them.&amp;nbsp; In a case where your business methods just call the dal&amp;#39;s methods, the interfaces/contracts will be the same so you may be able to share them.&lt;/p&gt;
&lt;p&gt;WCF gives you similar hosting options to Remoting and Web Services.&amp;nbsp; You can add a Service Reference and have svcutil.exe generate a proxy class which is virtually identical to what you did with web services. Hosting them is the easy part and if you can run a Console application and remember to put Console.Readline at the end of it, you can start a service host.&amp;nbsp; There&amp;#39;s about a zillion examples out there and it&amp;#39;s usually one of the first things covered in WCF so I&amp;#39;m leaving that alone for now.&lt;/p&gt;
&lt;p&gt;On the client, you can add a service reference as I said. However that is not without its problems and you may want a little more flexibility. If you want to create your own proxies, there are two primary methods (outside of svcutil related approaches). Let&amp;#39;s say you have the following interface:&lt;/p&gt;&lt;code&gt;
&lt;p&gt;&lt;font color="#0000ff"&gt;namespace&lt;/font&gt; Cuckooz.Sample.WCFStripClub&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp; [&lt;font color="#008080"&gt;DataContract&lt;/font&gt;]&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#0000ff"&gt;enum&lt;/font&gt; BounceLevel{&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;font color="#008080"&gt;EnumMember&lt;/font&gt;]&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Lame,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;font color="#008080"&gt;EnumMember&lt;/font&gt;]&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Woot,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;font color="#008080"&gt;EnumMember&lt;/font&gt;]&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; YeahBaby&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; };&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;font color="#008080"&gt;DataContract&lt;/font&gt;]&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;font color="#0000ff"&gt;public enum&lt;/font&gt; PoleManeuver{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;font color="#008080"&gt;EnumMember&lt;/font&gt;]&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Standard,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;font color="#008080"&gt;EnumMember&lt;/font&gt;]&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LookMaNoHands,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;font color="#008080"&gt;EnumMember&lt;/font&gt;]&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; UpsideDownLookMaNoHands&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; };&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;font color="#008080"&gt;ServiceContract&lt;/font&gt;]&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color="#0000ff"&gt; public interface&lt;/font&gt; IStripper&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;font color="#008080"&gt;OperationContract&lt;/font&gt;]&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;font color="#008080"&gt;String&lt;/font&gt; Bounce(&lt;font color="#008080"&gt;BounceLevel&lt;/font&gt; bouncin);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;font color="#008080"&gt;OperationContract&lt;/font&gt;]&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;font color="#008080"&gt;String&lt;/font&gt; SlideDownPoll(&lt;font color="#008080"&gt;PoleManeuver&lt;/font&gt; maneuver);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;font color="#008080"&gt;OperationContract&lt;/font&gt;]&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color="#0000ff"&gt; long&lt;/font&gt; MilkSuckerForCash(&lt;font color="#008080"&gt;String&lt;/font&gt; customerName);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;}&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;One approach is to create your own Proxy class , inheriting from ClientBase and passing in the type of the interface, while implementing the interface.&amp;nbsp; Pay attention to the implementations of this class:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&lt;font color="#0000ff"&gt;namespace&lt;/font&gt; Cuckooz.Sample.WCFStripClub&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;font color="#0000ff"&gt;public partial class&lt;/font&gt; &lt;font color="#008080"&gt;PurePlatinumServiceClient&lt;/font&gt; : &lt;font color="#008080"&gt;ClientBase&lt;/font&gt;&amp;lt;&lt;font color="#008080"&gt;IStripper&lt;/font&gt;&amp;gt;, &lt;font color="#008080"&gt;IStripper&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;font color="#0000ff"&gt;public&lt;/font&gt; PurePlatinumServiceClient() { }&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;font color="#0000ff"&gt;public&lt;/font&gt; PurePlatinumServiceClient(&lt;font color="#008080"&gt;String&lt;/font&gt; endpointConfigurationName) : &lt;font color="#0000ff"&gt;base&lt;/font&gt;(endpointConfigurationName) { }&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;font color="#0000ff"&gt;public&lt;/font&gt; PurePlatinumServiceClient(&lt;font color="#008080"&gt;String&lt;/font&gt; endpointConfigurationName, &lt;font color="#008080"&gt;String&lt;/font&gt; remoteAddress) : &lt;font color="#0000ff"&gt;base&lt;/font&gt;(endpointConfigurationName, remoteAddress) { }&lt;/code&gt;&lt;/p&gt;&lt;code&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;font color="#0000ff"&gt;public&lt;/font&gt; PurePlatinumServiceClient(&lt;font color="#008080"&gt;Binding&lt;/font&gt; binding, &lt;font color="#008080"&gt;EndpointAddress&lt;/font&gt; remoteAddress) : &lt;font color="#0000ff"&gt;base&lt;/font&gt;(binding, remoteAddress) { }&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;font color="#0000ff"&gt;public&lt;/font&gt; &lt;font color="#008080"&gt;String&lt;/font&gt; Bounce(&lt;font color="#008080"&gt;BounceLevel&lt;/font&gt; bouncin)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;font color="#0000ff"&gt;return base&lt;/font&gt;.Channel.Bounce(bouncin);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;font color="#0000ff"&gt;public&lt;/font&gt; String SlideDownPoll(&lt;font color="#008080"&gt;PoleManeuver&lt;/font&gt; maneuver)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;font color="#0000ff"&gt;return base&lt;/font&gt;.Channel.SlideDownPoll(maneuver);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;font color="#0000ff"&gt;public long&lt;/font&gt; MilkSuckerForCash(&lt;font color="#008080"&gt;String&lt;/font&gt; customerName)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;font color="#0000ff"&gt;return base&lt;/font&gt;.Channel.SlideDownPoll(&lt;font color="#008080"&gt;customerName&lt;/font&gt;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;}&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Note that b/c we are passing in the interface as a generic type parameter to ClientBase, we can refer to it through base.Channel.MethodName.&lt;/p&gt;
&lt;p&gt;You will need to have an endpoint configured in order to call the service and you should give the endpoint a name to make things easy.&amp;nbsp; In this case, I have a namedPipe endpoint configured named &amp;quot;NamedPipe&amp;quot;. With that in place, you simply need to create an instance of your proxy and have at it:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&lt;font color="#008080"&gt;PurePlatinumServiceClient&lt;/font&gt; dancerProxy = new &lt;font color="#008080"&gt;PurePlatinumServiceClient&lt;/font&gt;(&amp;quot;&lt;font color="#993300"&gt;NamedPipe&lt;/font&gt;&amp;quot;);&lt;br /&gt;&lt;font color="#008080"&gt;Console&lt;/font&gt;.WriteLine(dancerProxy.Bounce(&lt;font color="#008080"&gt;BounceLevel&lt;/font&gt;.YeahBaby));&lt;br /&gt;&lt;font color="#008080"&gt;Console&lt;/font&gt;.WriteLine(dancerProxy.SlideDownPoll(&lt;font color="#008080"&gt;PoleManeuver&lt;/font&gt;.UpsideDownLookMaNoHands));&lt;br /&gt;&lt;font color="#008080"&gt;Console&lt;/font&gt;.WriteLine(dancerProxy.MilkSuckerForCash(&amp;quot;&lt;font color="#993300"&gt;Peter Griffin&lt;/font&gt;&amp;quot;));&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;If you are going to create your proxies like this, do yourself a favor and use CodeSmith, some other template, or if you&amp;#39;re just really hard up, copy and paste where applicable - it&amp;#39;ll save you a lot of time.&lt;/p&gt;
&lt;p&gt;If you don&amp;#39;t want to go this route though, you can skip the whole proxy altogether.&amp;nbsp; Using the ChannelFactory class, you can specify the same interface we used above and create a new ChannelFactory.&amp;nbsp; Remember to name your endpoints in the configuration file so that you can refer to them. Otherwise, you&amp;#39;ll need to specify the endpoint hard code style - which is lame.&amp;nbsp; Once you&amp;#39;ve done that, you instantiate an IYourInterface object using the CreateChannel method of the ChannelFactory you just created.&amp;nbsp; Then, you should cast it to an IDisposable object and throw it in a using block, and have at it from there. Note, you don&amp;#39;t have to use IDispose but the other approach is to cast it as a ICommuncationObject and then call Close.&amp;nbsp; For the money, it&amp;#39;s easier and safer to just go the IDispose route. So the code below is functionally equivalent to the preceding block:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&lt;font color="#008080"&gt;ChannelFactory&lt;/font&gt;&amp;lt;&lt;font color="#008080"&gt;IStripper&lt;/font&gt;&amp;gt; stripperFactory = new &lt;font color="#008080"&gt;ChannelFactory&lt;/font&gt;&amp;lt;&lt;font color="#008080"&gt;IStripper&lt;/font&gt;&amp;gt;(&amp;quot;&lt;font color="#993300"&gt;NamedPipe&lt;/font&gt;&amp;quot;);&lt;br /&gt;&lt;font color="#008080"&gt;IStripper&lt;/font&gt; serviceInstance = stripperFactory.CreateChannel();&lt;br /&gt;using (serviceInstance as &lt;font color="#008080"&gt;IDisposable&lt;/font&gt;)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp; &lt;font color="#008080"&gt;Console&lt;/font&gt;.WriteLine(serviceInstance.Bounce(&lt;font color="#008080"&gt;BounceLevel&lt;/font&gt;.Woot));&lt;br /&gt;&amp;nbsp;&amp;nbsp; &lt;font color="#008080"&gt;Console&lt;/font&gt;.WriteLine(serviceInstance.SlideDownPoll(&lt;font color="#008080"&gt;PoleManeuver&lt;/font&gt;.LookMaNoHands));&lt;br /&gt;&amp;nbsp;&amp;nbsp; &lt;font color="#008080"&gt;Console&lt;/font&gt;.WriteLine(serviceInstance.MilkSuckerForCash(&amp;quot;&lt;font color="#993300"&gt;Peter Griffin&lt;/font&gt;&amp;quot;));&amp;nbsp;&lt;br /&gt;}&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Either of these approaches provides a ton of flexibility. For instance, you can create several endpoints, look at the environment and then decide which endpoint you want to talk on, hence, which binding you are going to use. Similarly, if you had several services you could easily change the execution to use on over the other ones.&amp;nbsp; All in all it really couldn&amp;#39;t be simpler and in this case, the hardest part of the equation is going to be setting up your configuration file properly.&lt;/p&gt;
&lt;p&gt;If I have time tomorrow I&amp;#39;ll post the next lesson which uses Duplexing, there&amp;#39;s a lot of potential with this interface and service when you enhance it with duplexing ;-)&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Silverlight for Windows Mobile</title><link>http://msmvps.com/blogs/williamryan/archive/2008/03/17/silverlight-for-windows-mobile.aspx</link><pubDate>Mon, 17 Mar 2008 05:00:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1545999</guid><dc:creator>William</dc:creator><description>&lt;p&gt;Speaking of new features that should help Windows Mobile remain the dominant player in the market, &lt;a href="http://silverlight.net/learn/mobile.aspx"&gt;a mobile version of Silverlight is going to be coming down the highway&lt;/a&gt;&amp;nbsp;.&lt;/p&gt;
&lt;p&gt;The good news:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;div&gt;Expected release is Q2 - 2008&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;div&gt;You can use Expression Blend to develop it with.&amp;nbsp; So you won&amp;#39;t need a new or additional IDE&lt;/div&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;The bad news:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;div&gt;It will be Silverlight 1.0&lt;/div&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;I know, the teeth on that horse you gave me are a little crooked.&amp;nbsp; Response time is really going to be the big factor here... if it&amp;#39;s fast and works right, this is going to be a huge, HUGE, feature that will open many doors to mobile development.&amp;nbsp; &lt;/p&gt;</description></item><item><title>Dabbling in LINQ to ADO.NET</title><link>http://msmvps.com/blogs/williamryan/archive/2008/01/05/dabbling-in-linq-to-ado-net.aspx</link><pubDate>Sat, 05 Jan 2008 06:00:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1439881</guid><dc:creator>William</dc:creator><description>&lt;p&gt;I&amp;#39;ll be doing a training seminar in Stockholm next month and I&amp;#39;ve been trying to create some compelling examples to illustrate various concepts.&amp;nbsp; Although it&amp;#39;s keeping me busy, there&amp;#39;s&amp;nbsp;a&amp;nbsp; lot I&amp;#39;ve been working on that&amp;#39;s blogworthy.&lt;/p&gt;
&lt;p&gt;One concept in LINQ to SQL that&amp;#39;s I am pretty fond of is the use of Entities. There&amp;#39;s so much you can do with Entities that it would take quite a few posts to do them justice, but I&amp;#39;ll show a simple example of how they can be used.&amp;nbsp; Assuming we&amp;#39;re using SQL Server 2005 for this example, I have a database table with the following table definition:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;GO &lt;font color="#339966"&gt;/****** Object: Table [dbo].[Bank] Script Date: 01/05/2008 21:14:48 ******/&lt;/font&gt; &lt;br /&gt;&lt;font color="#0000ff"&gt;SET ANSI_NULLS ON&lt;/font&gt; &lt;br /&gt;GO&lt;br /&gt;&lt;font color="#0000ff"&gt;SET QUOTED_IDENTIFIER ON &lt;/font&gt;&lt;/code&gt;&lt;code&gt;&lt;font color="#0000ff"&gt;GO SET ANSI_PADDING ON&lt;/font&gt; &lt;br /&gt;GO&lt;br /&gt;&lt;font color="#0000ff"&gt;CREATE TABLE&lt;/font&gt; [dbo].[Bank](&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [BankID] [int] &lt;font color="#0000ff"&gt;IDENTITY&lt;/font&gt;(1,1) NOT NULL,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [Name] [varchar](150) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[URL] [varchar](50) &lt;font color="#0000ff"&gt;COLLATE&lt;/font&gt; SQL_Latin1_General_CP1_CI_AS NULL, &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [bigLogo] [varchar](50) &lt;font color="#0000ff"&gt;COLLATE&lt;/font&gt; SQL_Latin1_General_CP1_CI_AS NULL, &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [smallogo] [varchar](50) &lt;font color="#0000ff"&gt;COLLATE&lt;/font&gt; SQL_Latin1_General_CP1_CI_AS NULL, &lt;br /&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CONSTRAINT&lt;/font&gt; [PK_Bank] &lt;font color="#0000ff"&gt;PRIMARY KEY CLUSTERED&lt;/font&gt; (&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [BankID] ASC&amp;nbsp;)&lt;br /&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WITH&lt;/font&gt; (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = &lt;font color="#0000ff"&gt;OFF&lt;/font&gt;, IGNORE_DUP_KEY =&lt;font color="#0000ff"&gt;&amp;nbsp;OFF&lt;br /&gt;&lt;/font&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) &lt;br /&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ON [PRIMARY] )&lt;br /&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ON &lt;/font&gt;[PRIMARY] &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; GO&lt;br /&gt;&lt;font color="#0000ff"&gt;SET ANSI_PADDING OFF&lt;/font&gt; &lt;/code&gt;&lt;/p&gt;
&lt;p&gt;So the first thing we need to do is create a class with the same definition (note, if you are using a member name that&amp;#39;s the same as the column name in the db, no additional steps need taken. If you use different names, then you need to specify a Name value .&amp;nbsp; Field names are not case sensitive [meaning as long as they have the same spelling as the field in the db, the capitalization can be different]). So you use [Column(Name=&amp;quot;DBColumnName&amp;quot;)] public Type AliasNameYouWantToUse&lt;/p&gt;&lt;code&gt;&lt;font color="#0000ff"&gt;using&lt;/font&gt; System.Linq;&lt;br /&gt;&lt;font color="#0000ff"&gt;using&lt;/font&gt; System.Linq.Expressions; &lt;br /&gt;&lt;font color="#0000ff"&gt;using&lt;/font&gt; System.Data.Linq.Mapping;&lt;br /&gt;&lt;font color="#0000ff"&gt;namespace&lt;/font&gt; Ryan.Samples.Linq.ADONET {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;font color="#33cccc"&gt;Table&lt;/font&gt;(Name=&lt;font color="#993366"&gt;&amp;quot;Bank&amp;quot;&lt;/font&gt;)] &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;font color="#0000ff"&gt;public&lt;/font&gt; class &lt;font color="#33cccc"&gt;Bank&lt;/font&gt; { &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;font color="#33cccc"&gt;Column&lt;/font&gt;]&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;font color="#0000ff"&gt;public&lt;/font&gt; Int32 BankID;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;font color="#33cccc"&gt;Column&lt;/font&gt;]&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;font color="#0000ff"&gt;public&lt;/font&gt; String Name; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;font color="#33cccc"&gt;Column&lt;/font&gt;] &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;font color="#0000ff"&gt;public&lt;/font&gt; String URL;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;font color="#33cccc"&gt;Column&lt;/font&gt;] &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;font color="#0000ff"&gt;public&lt;/font&gt; String biglogo;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;font color="#33cccc"&gt;Column&lt;/font&gt;]&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;font color="#0000ff"&gt;public&lt;/font&gt; String smallogo;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;} &lt;/code&gt;
&lt;p&gt;Now, we have a Bank class which corresponds to the Bank table in the database.&amp;nbsp; For this sample, I created a static class with a static property named Globals and ConnectionString respectively.&amp;nbsp; Now, I compose a quick LINQ query to retrieve all of the data in the table except records where the Bank&amp;#39;s Name is PNC:&lt;/p&gt;&lt;code&gt;&lt;font color="#3366ff"&gt;static&lt;/font&gt; &lt;font color="#3366ff"&gt;void&lt;/font&gt; Main(&lt;font color="#3366ff"&gt;string&lt;/font&gt;[] args)&lt;br /&gt;{&lt;br /&gt;&lt;font color="#33cccc"&gt;&amp;nbsp;&amp;nbsp; DataContext&lt;/font&gt; db = new &lt;font color="#33cccc"&gt;DataContext&lt;/font&gt;(&lt;font color="#33cccc"&gt;Globals&lt;/font&gt;.ConnectionString);&lt;br /&gt;&lt;font color="#33cccc"&gt;&amp;nbsp;&amp;nbsp; Table&lt;/font&gt; &amp;lt;&lt;font color="#33cccc"&gt;Banks&lt;/font&gt;&amp;gt; = db.GetTable&amp;lt;&lt;font color="#33cccc"&gt;Bank&lt;/font&gt;&amp;gt;();&lt;br /&gt;&lt;br /&gt;&lt;font color="#3366ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var&lt;/font&gt; query =&lt;br /&gt;&lt;font color="#3366ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from&lt;/font&gt; b &lt;font color="#3366ff"&gt;in&lt;/font&gt; Banks&lt;br /&gt;&lt;font color="#3366ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where&lt;/font&gt; b.Name != &lt;font color="#993366"&gt;&amp;quot;PNC&amp;quot;&lt;/font&gt;&lt;br /&gt;&lt;font color="#3366ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;select&lt;/font&gt; &lt;font color="#3366ff"&gt;new&lt;/font&gt; { b.BankID, b.Name, b.URL };&lt;br /&gt;&lt;br /&gt;&lt;font color="#3366ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; foreach&lt;/font&gt; (&lt;font color="#3366ff"&gt;var&lt;/font&gt; row &lt;font color="#3366ff"&gt;in&lt;/font&gt; query)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&lt;font color="#33cccc"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Console&lt;/font&gt;.WriteLine(row);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&lt;font color="#33cccc"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Console&lt;/font&gt;.ReadLine();&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;
&lt;p&gt;The syntax is pretty straightforward on the LINQ side so it doesn&amp;#39;t really need explaining - if you can&amp;#39;t tell what it&amp;#39;s doing though, it&amp;#39;s selecting each value that doesn&amp;#39; t have &amp;#39;PNC&amp;#39; as a name.&amp;nbsp; The Select statement is using a new C# language feature known as Anonymous types meaning that, a new type is being created without a traditional definition - that&amp;#39;s why the new keyword is used.&lt;/p&gt;
&lt;p&gt;When I first learned LINQ though, I wondered how this worked.&amp;nbsp; Was the whole table retrieved from the database and then records restricted via LINQ?&amp;nbsp; If so, this would seem very wasteful b/c by virtue of the restriction, you know you&amp;#39;re only using a subset of the total values so why pull down everything?&amp;nbsp; Fortunately that&amp;#39;s not what happens.&amp;nbsp; GetTable doesn&amp;#39;t acttually pull down everything from the table - it&amp;#39;s merely an instruction about how to generate the query it will use. As you probably have noticed, nowhere in here have we defined anything reminiscent of the CommandText property you&amp;#39;d use with a IDBCommand object.&amp;nbsp; To prove that you aren&amp;#39;t pulling down a whole table as you might with the old TableDirect instruction, run profiler before this code block executes.&amp;nbsp; The results will show the following (assuming you are logging the same values).&lt;/p&gt;
&lt;p&gt;Here&amp;#39;s the resulting output:&lt;/p&gt;
&lt;p&gt;&lt;font color="#ff0000"&gt;exec sp_executesql N&amp;#39;SELECT [t0].[BankID], [t0].[Name], [t0].[URL]&lt;br /&gt;FROM [Bank] AS [t0]&lt;br /&gt;WHERE [t0].[Name] &amp;lt;&amp;gt; @p0&amp;#39;,N&amp;#39;@p0 nvarchar(3)&amp;#39;,@p0=N&amp;#39;PNC&amp;#39;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;And just for the record, nothing before this ran a query on this table let alone one without a restriction.&amp;nbsp; The output for running this code is shown below:&lt;/p&gt;&lt;font size="1"&gt;
&lt;p&gt;{ BankID = 1, Name = Bank of America, URL = www.bankofamerica.com }&lt;/p&gt;
&lt;p&gt;{ BankID = 2, Name = Citi Bank, URL = www.citibank.com }&lt;/p&gt;
&lt;p&gt;{ BankID = 3, Name = 1st Tennessee, URL = http://www.firsttennessee.com/ }&lt;/p&gt;
&lt;p&gt;{ BankID = 4, Name = Citi Group, URL = www.citigroup.com }&lt;/p&gt;
&lt;p&gt;{ BankID = 5, Name = JP Morgan, URL = www.jpmorgan.com }&lt;/p&gt;
&lt;p&gt;{ BankID = 7, Name = UMB, URL = www.umb.com }&lt;/p&gt;
&lt;p&gt;{ BankID = 8, Name = US Bank, URL = www.usbank.co }&lt;/p&gt;
&lt;p&gt;{ BankID = 9, Name = BMO Financial Group, URL = www4.bmo.com/ }&lt;/p&gt;
&lt;p&gt;{ BankID = 10, Name = M &amp;amp; T, URL = http://www.mandtbank.com/ }&lt;/p&gt;
&lt;p&gt;{ BankID = 11, Name = National City, URL = http://www.nationalcity.com }&lt;/p&gt;&lt;/font&gt;
&lt;p&gt;This brings up one other point... I could have changed the Console.WriteLine to just write out one or more of the properties of &amp;#39;row&amp;#39;.&amp;nbsp; In general, I make a rule of *always* overriding the ToString() method in any object I create just so that I can use it for meaningful information. With LINQ in particular, this becomes particularly useful b/c had I not used an anonymous type, (so the last line would read &amp;#39;select b;&amp;#39; instead of &amp;#39;select new {b.BankID, b.Name, b.URL}; I would have had the following useless output:&lt;/p&gt;&lt;font size="1"&gt;
&lt;p&gt;Ryan.Samples.Linq.ADONET.Bank&lt;/p&gt;
&lt;p&gt;Ryan.Samples.Linq.ADONET.Bank&lt;/p&gt;
&lt;p&gt;Ryan.Samples.Linq.ADONET.Bank&lt;/p&gt;
&lt;p&gt;Ryan.Samples.Linq.ADONET.Bank&lt;/p&gt;
&lt;p&gt;Ryan.Samples.Linq.ADONET.Bank&lt;/p&gt;
&lt;p&gt;Ryan.Samples.Linq.ADONET.Bank&lt;/p&gt;
&lt;p&gt;Ryan.Samples.Linq.ADONET.Bank&lt;/p&gt;
&lt;p&gt;Ryan.Samples.Linq.ADONET.Bank&lt;/p&gt;
&lt;p&gt;Ryan.Samples.Linq.ADONET.Bank&lt;/p&gt;
&lt;p&gt;Ryan.Samples.Linq.ADONET.Bank&lt;/p&gt;&lt;/font&gt;
&lt;p&gt;&amp;nbsp;I could get around that by formatting the output in the Console.WriteLine method but that&amp;#39;s might inelegant. Instead, by overriding the ToString() method, I can get the following output instead:&lt;/p&gt;
&lt;p&gt;&amp;lt;I&amp;#39;&amp;#39;ve truncated several records just for the sake of readability&amp;gt;&lt;/p&gt;&lt;font size="1"&gt;
&lt;p&gt;BankID - 1&lt;/p&gt;
&lt;p&gt;Name - Bank of America&lt;/p&gt;
&lt;p&gt;URL - www.bankofamerica.com&lt;/p&gt;
&lt;p&gt;biglogo - baclogo.jpg&lt;/p&gt;
&lt;p&gt;smallogo - bigbanksmall.jpg&lt;/p&gt;
&lt;p&gt;BankID - 2&lt;/p&gt;
&lt;p&gt;Name - Citi Bank&lt;/p&gt;
&lt;p&gt;URL - www.citibank.com&lt;/p&gt;
&lt;p&gt;biglogo - citibanklogo.jpg&lt;/p&gt;
&lt;p&gt;smallogo - bigbanksmall.jpg&lt;/p&gt;
&lt;p&gt;BankID - 3&lt;/p&gt;
&lt;p&gt;Name - 1st Tennessee&lt;/p&gt;
&lt;p&gt;URL - http://www.firsttennessee.com/&lt;/p&gt;
&lt;p&gt;biglogo - 1sttennlogo.jpg&lt;/p&gt;
&lt;p&gt;smallogo - 1sttennsmall.jpg&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;Needless to say, this is a lot more useful than simply knowing the fully qualified object name.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;/font&gt;</description></item></channel></rss>