<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: WCF: &#8220;Slicing&#8221; objects on serialization</title>
	<atom:link href="http://www.janus-net.de/2008/01/13/wcf-slicing-objects-on-serialization/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.janus-net.de/2008/01/13/wcf-slicing-objects-on-serialization/</link>
	<description>just another line in the file</description>
	<lastBuildDate>Thu, 10 Jun 2010 00:25:18 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: Ross</title>
		<link>http://www.janus-net.de/2008/01/13/wcf-slicing-objects-on-serialization/comment-page-1/#comment-883</link>
		<dc:creator>Ross</dc:creator>
		<pubDate>Tue, 25 Nov 2008 22:33:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.janus-net.de/2008/01/13/wcf-slicing-objects-on-serialization/#comment-883</guid>
		<description>OK, I kind of figured it out.

I used the ServiceKnowType as you suggested but added it to the ServiceOperation rather than the ServiceContract (eitherway way worked, but I wanted to be more specific).

The reason why it wasn&#039;t showing up because my Service Contract only had one method that returned a String type.  As soon as I changed the return type to Object it showed up.

[Serializable]    
public class Ping3Result
{       
     public String Name;
     public String GID;
}
            
[ServiceContract]        
public interface IMyPingTest
{
     [OperationContract(ProtectionLevel = ProtectionLevel.Sign)]
     [ServiceKnownType(typeof(Ping3Result))]        
     Object Ping(String str);
}

Also, I needed to use the [Serializable] rather than [DataContract].  Again, either would have worked.  But in my context, i need to serialize the object using the XmlSerilaizer, sign and encrypt the final string (object).

And as stated before, it would have been queued into a database to be retrived by another application to decrypt, verify the signature then deseralize back to the correct object type.  To make matters simpler, I could have just used XSD for that particular object as the real consumer of the object doesn&#039;t care about web services or WCF :)

Thanks for you help!!!  You lead me in the right direction.

Ross</description>
		<content:encoded><![CDATA[<p>OK, I kind of figured it out.</p>
<p>I used the ServiceKnowType as you suggested but added it to the ServiceOperation rather than the ServiceContract (eitherway way worked, but I wanted to be more specific).</p>
<p>The reason why it wasn&#8217;t showing up because my Service Contract only had one method that returned a String type.  As soon as I changed the return type to Object it showed up.</p>
<p>[Serializable]<br />
public class Ping3Result<br />
{<br />
     public String Name;<br />
     public String GID;<br />
}</p>
<p>[ServiceContract]<br />
public interface IMyPingTest<br />
{<br />
     [OperationContract(ProtectionLevel = ProtectionLevel.Sign)]<br />
     [ServiceKnownType(typeof(Ping3Result))]<br />
     Object Ping(String str);<br />
}</p>
<p>Also, I needed to use the [Serializable] rather than [DataContract].  Again, either would have worked.  But in my context, i need to serialize the object using the XmlSerilaizer, sign and encrypt the final string (object).</p>
<p>And as stated before, it would have been queued into a database to be retrived by another application to decrypt, verify the signature then deseralize back to the correct object type.  To make matters simpler, I could have just used XSD for that particular object as the real consumer of the object doesn&#8217;t care about web services or WCF <img src='http://www.janus-net.de/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Thanks for you help!!!  You lead me in the right direction.</p>
<p>Ross</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ross</title>
		<link>http://www.janus-net.de/2008/01/13/wcf-slicing-objects-on-serialization/comment-page-1/#comment-882</link>
		<dc:creator>Ross</dc:creator>
		<pubDate>Mon, 24 Nov 2008 21:52:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.janus-net.de/2008/01/13/wcf-slicing-objects-on-serialization/#comment-882</guid>
		<description>Thanks, I&#039;ll take a look at that.

BTW - I can&#039;t use the ProtectionLevel attribute.  When the caller recieves the result, they must put it on the queue and the object must remain encrypted.  The problem with WCF&#039;s ProtectionLevel is that it&#039;s point-to-point, not end-to-end.  Meaning that the message will be signed and encrypted across the wire but when the receiving WCF client recieves it, WCF will automatically decrypt and verify the signature.  At least that&#039;s how it seems to work.

I&#039;ll back to you when I find a resolution.  That might be a few days the way things are going :)  I&#039;ll retry the SeviceKnownType attribute one more time.  but when I use the svcutil to generate the proxy, I don&#039;t find any reference to it.

Thanks for your help thus far.

Ross</description>
		<content:encoded><![CDATA[<p>Thanks, I&#8217;ll take a look at that.</p>
<p>BTW &#8211; I can&#8217;t use the ProtectionLevel attribute.  When the caller recieves the result, they must put it on the queue and the object must remain encrypted.  The problem with WCF&#8217;s ProtectionLevel is that it&#8217;s point-to-point, not end-to-end.  Meaning that the message will be signed and encrypted across the wire but when the receiving WCF client recieves it, WCF will automatically decrypt and verify the signature.  At least that&#8217;s how it seems to work.</p>
<p>I&#8217;ll back to you when I find a resolution.  That might be a few days the way things are going <img src='http://www.janus-net.de/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />   I&#8217;ll retry the SeviceKnownType attribute one more time.  but when I use the svcutil to generate the proxy, I don&#8217;t find any reference to it.</p>
<p>Thanks for your help thus far.</p>
<p>Ross</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stj</title>
		<link>http://www.janus-net.de/2008/01/13/wcf-slicing-objects-on-serialization/comment-page-1/#comment-881</link>
		<dc:creator>stj</dc:creator>
		<pubDate>Mon, 24 Nov 2008 21:27:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.janus-net.de/2008/01/13/wcf-slicing-objects-on-serialization/#comment-881</guid>
		<description>Hi,

adding ServiceKnownType should work. If the type doesn&#039;t show up in your wsdl take a look at imported shemas. There should be lines reading something like this:
&lt;wsdl:import namespace=&quot;MyServiceNamespace&quot; location=&quot;http://localhost/MyService?wsdl=wsdl0&quot;/&gt;
&lt;xsd:import schemaLocation=&quot;http://MyService/HelloWorld?xsd=xsd0&quot; namespace=&quot;http://schemas.microsoft.com/2003/10/Serialization/&quot;/&gt;
...


If you need to deal with encryption/decryption and signing messages you may want to have a look at WCF&#039;s security features. Here are some links that might be a good starting point:

http://www.code-magazine.com/Article.aspx?quickid=0611051

http://msdn.microsoft.com/en-us/library/aa347791.aspx

http://msdn.microsoft.com/en-us/library/aa347692.aspx

http://www.codeplex.com/WCFSecurityGuide</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>adding ServiceKnownType should work. If the type doesn&#8217;t show up in your wsdl take a look at imported shemas. There should be lines reading something like this:<br />
&lt;wsdl:import namespace=&#8221;MyServiceNamespace&#8221; location=&#8221;http://localhost/MyService?wsdl=wsdl0&#8243;/&gt;<br />
&lt;xsd:import schemaLocation=&#8221;http://MyService/HelloWorld?xsd=xsd0&#8243; namespace=&#8221;http://schemas.microsoft.com/2003/10/Serialization/&#8221;/&gt;<br />
&#8230;</p>
<p>If you need to deal with encryption/decryption and signing messages you may want to have a look at WCF&#8217;s security features. Here are some links that might be a good starting point:</p>
<p><a href="http://www.code-magazine.com/Article.aspx?quickid=0611051" rel="nofollow">http://www.code-magazine.com/Article.aspx?quickid=0611051</a></p>
<p><a href="http://msdn.microsoft.com/en-us/library/aa347791.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/aa347791.aspx</a></p>
<p><a href="http://msdn.microsoft.com/en-us/library/aa347692.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/aa347692.aspx</a></p>
<p><a href="http://www.codeplex.com/WCFSecurityGuide" rel="nofollow">http://www.codeplex.com/WCFSecurityGuide</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ross</title>
		<link>http://www.janus-net.de/2008/01/13/wcf-slicing-objects-on-serialization/comment-page-1/#comment-880</link>
		<dc:creator>Ross</dc:creator>
		<pubDate>Mon, 24 Nov 2008 20:29:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.janus-net.de/2008/01/13/wcf-slicing-objects-on-serialization/#comment-880</guid>
		<description>Hi I already tried to add the [ServiceKnownType(typeof(MyResult))] to the interface but it doesn&#039;t add this to the wsdl.

Btw: How does the caller know how to deserialize the string? You should consider changing your interface definiton!

How would I go about changing my interface definition to somehow state that I require the return string to be decrypted, verify the signature and deseralize the string to the MyResult type?

I really appreciate you help on this.  It&#039;s funny, I can do this in the old way be adding the type to the service interface, but in WCF I can&#039; seem to find the anwser yet.  I know it&#039;s possible.  I might want to use the XmlSerializer in place of the DataContractSerializer and see if that works.</description>
		<content:encoded><![CDATA[<p>Hi I already tried to add the [ServiceKnownType(typeof(MyResult))] to the interface but it doesn&#8217;t add this to the wsdl.</p>
<p>Btw: How does the caller know how to deserialize the string? You should consider changing your interface definiton!</p>
<p>How would I go about changing my interface definition to somehow state that I require the return string to be decrypted, verify the signature and deseralize the string to the MyResult type?</p>
<p>I really appreciate you help on this.  It&#8217;s funny, I can do this in the old way be adding the type to the service interface, but in WCF I can&#8217; seem to find the anwser yet.  I know it&#8217;s possible.  I might want to use the XmlSerializer in place of the DataContractSerializer and see if that works.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stj</title>
		<link>http://www.janus-net.de/2008/01/13/wcf-slicing-objects-on-serialization/comment-page-1/#comment-879</link>
		<dc:creator>stj</dc:creator>
		<pubDate>Mon, 24 Nov 2008 19:45:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.janus-net.de/2008/01/13/wcf-slicing-objects-on-serialization/#comment-879</guid>
		<description>Hi Ross,

I&#039;m not sure if I really understand what you want to accomplish. 
Do you only want your type MyResult shown up in your WSDL without using the type in any of your methods?
If you do try adding the ServiceKnownType attribute to your interface like this:

[ServiceContract]
[ServiceKnownType(typeof(MyResult))]
public interface IMyService
{
// ... 
}

This will lead to the following definition beeing added to your wsdl:

&lt;xs:schema elementFormDefault=&quot;qualified&quot; targetNamespace=&quot;http://schemas.datacontract.org/2004/07/Contracts&quot;&gt;
	&lt;xs:complexType name=&quot;MyResult&quot;&gt;
		&lt;xs:sequence&gt;
			&lt;xs:element minOccurs=&quot;0&quot; name=&quot;SomeValue&quot; nillable=&quot;true&quot; type=&quot;xs:string&quot;/&gt;
		&lt;/xs:sequence&gt;
	&lt;/xs:complexType&gt;
	&lt;xs:element name=&quot;MyResult&quot; nillable=&quot;true&quot; type=&quot;tns:MyResult&quot;/&gt;
&lt;/xs:schema&gt;


Btw: How does the caller know how to deserialize the string? You should consider changing your interface definiton!</description>
		<content:encoded><![CDATA[<p>Hi Ross,</p>
<p>I&#8217;m not sure if I really understand what you want to accomplish.<br />
Do you only want your type MyResult shown up in your WSDL without using the type in any of your methods?<br />
If you do try adding the ServiceKnownType attribute to your interface like this:</p>
<p>[ServiceContract]<br />
[ServiceKnownType(typeof(MyResult))]<br />
public interface IMyService<br />
{<br />
// &#8230;<br />
}</p>
<p>This will lead to the following definition beeing added to your wsdl:</p>
<p>&lt;xs:schema elementFormDefault=&#8221;qualified&#8221; targetNamespace=&#8221;http://schemas.datacontract.org/2004/07/Contracts&#8221;&gt;<br />
	&lt;xs:complexType name=&#8221;MyResult&#8221;&gt;<br />
		&lt;xs:sequence&gt;<br />
			&lt;xs:element minOccurs=&#8221;0&#8243; name=&#8221;SomeValue&#8221; nillable=&#8221;true&#8221; type=&#8221;xs:string&#8221;/&gt;<br />
		&lt;/xs:sequence&gt;<br />
	&lt;/xs:complexType&gt;<br />
	&lt;xs:element name=&#8221;MyResult&#8221; nillable=&#8221;true&#8221; type=&#8221;tns:MyResult&#8221;/&gt;<br />
&lt;/xs:schema&gt;</p>
<p>Btw: How does the caller know how to deserialize the string? You should consider changing your interface definiton!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ross</title>
		<link>http://www.janus-net.de/2008/01/13/wcf-slicing-objects-on-serialization/comment-page-1/#comment-878</link>
		<dc:creator>Ross</dc:creator>
		<pubDate>Mon, 24 Nov 2008 19:07:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.janus-net.de/2008/01/13/wcf-slicing-objects-on-serialization/#comment-878</guid>
		<description>Hi I&#039;m not sure if you can help me here.  I have a method that I need to return a type but serialized as a string.  I want the caller to receive this string and deseralize it back to its orignal object type.  

So my question is, how do I include this type in the WSDL without having to declare it being used as a type in the ServiceContract definition?

[DataContract]
pubic class MyResult
{
   [DataMember]
   public String SomeValue;
}

[ServiceContract]
public interface IMyService
{
    [ServiceOperation]
    public String MyMethod(); // return a serialized object of type MyResult
}

I need to ensure that the result remains encrypted and signed without having WCF involved.

Any help would be greatly apprieciated,

Thanks,

Ross</description>
		<content:encoded><![CDATA[<p>Hi I&#8217;m not sure if you can help me here.  I have a method that I need to return a type but serialized as a string.  I want the caller to receive this string and deseralize it back to its orignal object type.  </p>
<p>So my question is, how do I include this type in the WSDL without having to declare it being used as a type in the ServiceContract definition?</p>
<p>[DataContract]<br />
pubic class MyResult<br />
{<br />
   [DataMember]<br />
   public String SomeValue;<br />
}</p>
<p>[ServiceContract]<br />
public interface IMyService<br />
{<br />
    [ServiceOperation]<br />
    public String MyMethod(); // return a serialized object of type MyResult<br />
}</p>
<p>I need to ensure that the result remains encrypted and signed without having WCF involved.</p>
<p>Any help would be greatly apprieciated,</p>
<p>Thanks,</p>
<p>Ross</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Turner</title>
		<link>http://www.janus-net.de/2008/01/13/wcf-slicing-objects-on-serialization/comment-page-1/#comment-832</link>
		<dc:creator>David Turner</dc:creator>
		<pubDate>Wed, 20 Feb 2008 16:44:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.janus-net.de/2008/01/13/wcf-slicing-objects-on-serialization/#comment-832</guid>
		<description>Follow-up on shared API design:

http://dkturner.blogspot.com/2008/02/shared-apis-part-1-of-4-why-and-how.html</description>
		<content:encoded><![CDATA[<p>Follow-up on shared API design:</p>
<p><a href="http://dkturner.blogspot.com/2008/02/shared-apis-part-1-of-4-why-and-how.html" rel="nofollow">http://dkturner.blogspot.com/2008/02/shared-apis-part-1-of-4-why-and-how.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Turner</title>
		<link>http://www.janus-net.de/2008/01/13/wcf-slicing-objects-on-serialization/comment-page-1/#comment-827</link>
		<dc:creator>David Turner</dc:creator>
		<pubDate>Fri, 15 Feb 2008 11:06:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.janus-net.de/2008/01/13/wcf-slicing-objects-on-serialization/#comment-827</guid>
		<description>Balls, it stripped out the &lt;T&gt; on RefBase.  I hope my meaning remains reasonably clear.</description>
		<content:encoded><![CDATA[<p>Balls, it stripped out the &lt;T&gt; on RefBase.  I hope my meaning remains reasonably clear.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Turner</title>
		<link>http://www.janus-net.de/2008/01/13/wcf-slicing-objects-on-serialization/comment-page-1/#comment-826</link>
		<dc:creator>David Turner</dc:creator>
		<pubDate>Fri, 15 Feb 2008 11:04:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.janus-net.de/2008/01/13/wcf-slicing-objects-on-serialization/#comment-826</guid>
		<description>Hiya

That&#039;s pretty much how I did it.  Great minds think alike :-).  I was already using a surrogate for other reasons, so it wasn&#039;t too much code.  Also, I didn&#039;t use a special attribute on the operations, I just made the GetObjectToSerialize method do a little more work, using reflection to decide if the actual type was a known type and assuming it needed to slice otherwise.  Oh, and I created a generic class called RefBase, which implemented the Slice() method (returning T).  So my transport objects all follow a similar pattern:

[DataContract] class FooRef : RefBase { [DataMember] int id = 0; /* etc */ }
[DataContract] class FooHeader : FooRef { /* summary info goes here for those services that need summaries */ }
[DataContract] class Foo : FooHeader { /* adds the rest of the detail */ }

Some additional commentary (I&#039;ll post more on my blog when I have the time):

1. The whole [KnownType] thing sucks.  Yes, it&#039;s handy when you need it, but I really haven&#039;t run into that many contracts that use polymorphic messages.  I&#039;ve found that one tends to write multiple operations rather than implement a choice{ } data-type.  That said, ASN.1 and most of the major protocols support choice-types, so I&#039;m glad WCF does too.  But it really should understand that if I don&#039;t specify choice, then I probably want to slice!  The one situation where I&#039;ve found choice-types really useful is when passing changesets.  But even then, it&#039;s probably better to do it as (BeginChangeset(), AddXXXChange, AddYYYChange, ..., CommitChangeset()).

2. On a slightly different point, when you really get into multi-tier programming, AOP starts to make a whole lot of sense.  I really, really don&#039;t want to re-implement my transport class on the server side and on the client side; and I&#039;m equally opposed to putting client or server logic in the (shared) service API library.  Another thing that I often want to do is aggregation (one UI facade representing multiple data objects).  All these things are good&#039;n&#039;easy with AOP.  Pity the CLR doesn&#039;t support injection (except when you start playing with ContextBoundObject, which is interesting but bad design, too special-casey, and I really am getting carried away here...).

I&#039;ve discussed (2) with my colleagues, and the best we&#039;ve come up with is:

namespace API {
  [DataContract] public class Customer {
    [DataMember] protected string name = null;
  }
}

namespace Server {
  public class Customer : API.Customer {
    public Customer(IDataRecord data) {
      base.name = data[&quot;Name&quot;] as string;
    }
  }
}

namespace Client {
  public class Customer : API.Customer, INotifyPropertyChanged {
    public string Name { get { return base.name; } set { base.name = value; OnPropertyChanged(&quot;Name&quot;); } }
  }
  /* etc... */
}

Alas, there are still many problems with this approach, which start to become apparent almost immediately.</description>
		<content:encoded><![CDATA[<p>Hiya</p>
<p>That&#8217;s pretty much how I did it.  Great minds think alike <img src='http://www.janus-net.de/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> .  I was already using a surrogate for other reasons, so it wasn&#8217;t too much code.  Also, I didn&#8217;t use a special attribute on the operations, I just made the GetObjectToSerialize method do a little more work, using reflection to decide if the actual type was a known type and assuming it needed to slice otherwise.  Oh, and I created a generic class called RefBase, which implemented the Slice() method (returning T).  So my transport objects all follow a similar pattern:</p>
<p>[DataContract] class FooRef : RefBase { [DataMember] int id = 0; /* etc */ }<br />
[DataContract] class FooHeader : FooRef { /* summary info goes here for those services that need summaries */ }<br />
[DataContract] class Foo : FooHeader { /* adds the rest of the detail */ }</p>
<p>Some additional commentary (I&#8217;ll post more on my blog when I have the time):</p>
<p>1. The whole [KnownType] thing sucks.  Yes, it&#8217;s handy when you need it, but I really haven&#8217;t run into that many contracts that use polymorphic messages.  I&#8217;ve found that one tends to write multiple operations rather than implement a choice{ } data-type.  That said, ASN.1 and most of the major protocols support choice-types, so I&#8217;m glad WCF does too.  But it really should understand that if I don&#8217;t specify choice, then I probably want to slice!  The one situation where I&#8217;ve found choice-types really useful is when passing changesets.  But even then, it&#8217;s probably better to do it as (BeginChangeset(), AddXXXChange, AddYYYChange, &#8230;, CommitChangeset()).</p>
<p>2. On a slightly different point, when you really get into multi-tier programming, AOP starts to make a whole lot of sense.  I really, really don&#8217;t want to re-implement my transport class on the server side and on the client side; and I&#8217;m equally opposed to putting client or server logic in the (shared) service API library.  Another thing that I often want to do is aggregation (one UI facade representing multiple data objects).  All these things are good&#8217;n'easy with AOP.  Pity the CLR doesn&#8217;t support injection (except when you start playing with ContextBoundObject, which is interesting but bad design, too special-casey, and I really am getting carried away here&#8230;).</p>
<p>I&#8217;ve discussed (2) with my colleagues, and the best we&#8217;ve come up with is:</p>
<p>namespace API {<br />
  [DataContract] public class Customer {<br />
    [DataMember] protected string name = null;<br />
  }<br />
}</p>
<p>namespace Server {<br />
  public class Customer : API.Customer {<br />
    public Customer(IDataRecord data) {<br />
      base.name = data["Name"] as string;<br />
    }<br />
  }<br />
}</p>
<p>namespace Client {<br />
  public class Customer : API.Customer, INotifyPropertyChanged {<br />
    public string Name { get { return base.name; } set { base.name = value; OnPropertyChanged(&#8220;Name&#8221;); } }<br />
  }<br />
  /* etc&#8230; */<br />
}</p>
<p>Alas, there are still many problems with this approach, which start to become apparent almost immediately.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

